Timing a command#

time COMMAND will tell you how long a command took to run:

The “user” and “system” times show how much CPU time was spent in user space and kernel space, respectively. In our case they are much smaller than the real time, because the sleep command uses barely any CPU, but they are counted per CPU, so they can actually exceed the elapsed time for a busy, multi–threaded program.

time prints the timing information even when interrupted.

For most regular programmers only the first line is interesting. It shows the actual amount of elapsed time, or “wall–clock” time.

It may be surprising that on a machine capable of processing billions of instructions per second the timing was off by a full 11 milliseconds. This is because sleep does not give any hard guarantees about how long it runs. It will try to run for approximately the given time, but we should never rely on it as an accurate time–keeper.

 

This page is a preview of The newline Guide to Bash Scripting

No discussions yet