I'm running Ubuntu 18.04 and am new to Ubuntu and Linux in general. I'm trying to measure the execution time of a command down to the millisecond. I would also like to append this time to a file, because I'm doing this a lot of times in a for loop. Finally, I would like to have the most simple and easily readable syntax.
Long story short : I would like the /usr/bin/time
command to return a result precise to the millisecond.
I have read other threads mentioning a time format environment variable, but never how to modify it.
Thanks in advance for the help.
EDIT : Taking all answers into account, the solution was something like
#!/bin/bash
ts=$(date +%s%N)
command
echo "formatting $((($(date +%s%N) - $ts)/1000000)) formatting" >> file_to_append_time_to
>
to cause the output of a command to write to a file,>>
to append to the file (rather than overwrite it). Have you even looked at the documentation?man time
tells you "The elapsed time is not collected atomically with the execution of the program; as a result, in bizarre circumstances .." which means I suspect you want more from it that it can accurately provide (or should be trusted for). It also has examples, or tryinfo time
which contains more info & examples! Have you tried looking yourself? – guiverc Oct 01 '18 at 21:36