15

The buitin bash command time gives milisecond precision of execution and GNU time (usually /usr/bin/time) gives centisecond precision. The times(2) syscall gives times in clocks, and 100 clocks = 1 second (usually), so the precision is like GNU time. So the question is what is bash time using so that it's more precise?

Kevin
  • 40,767
  • Hmmm... they both give milliseconds on my system... (FC16) – nico Dec 29 '11 at 17:44
  • Strange. What gives you printf("%d\n", sysconf(_SC_CLK_TCK)); should be 100 as I stated above. Someone have similar observations to mine: http://www.dirac.org/linux/time/ but still no explanation. – Łukasz Sowa Dec 29 '11 at 17:48
  • yes, in effect it gives 100... – nico Dec 29 '11 at 18:01
  • Then I have no idea why's that. GNU time is supposed to use times syscall which uses sysconf(_SC_CLK_TCK) to convert to seconds. – Łukasz Sowa Dec 29 '11 at 18:24
  • FWIW When you say "bash time", I assume you mean BSD time as that uses getrusage. – Dennis Feb 03 '17 at 17:48

1 Answers1

18

After some hardcore bash code examining I found out that bash time uses getrusage() and GNU time uses times(). getrusage() is far more precise because of microsecond resolution.

Kevin
  • 40,767