I am using GNU time for benchmarking and would like to measure real, user and sys time to the nearest millisecond. That is, I want to measure seconds to 3 decimal places, not the default 2. Does GNU time offer such an option?
It doesn't look like you could, the man page does list a number of formatting options, but there's no provision for setting the accuracy. For example,
%U seem to always give the output with two decimal places.
On the other hand, Bash's builtin
time does support setting the number of digits after the decimal point, up to 3, so you might be able to use it to get what you wanted. The
TIMEFORMAT environment variable controls the output format:
$ TIMEFORMAT='real: %3R user: %3U sys: %3S cpu: %P' bash -c 'time sleep 1.233' real: 1.234 user: 0.000 sys: 0.000 cpu: 0.00
Or just without setting
TIMEFORMAT, since the default output also shows three digits. It does separate minutes though:
$ bash -c 'time sleep 1.233' real 0m1.234s user 0m0.000s sys 0m0.000s
getrusage() system call gives the times as
struct timeval, so up to microseconds, so I suppose you could make your own implementation of
time to get more accuracy. A whole another thing is how accurate the numbers actually are.