Timing a command
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
sleepcommand uses barely any CPU, but they are counted per CPU, so they can actually exceed the elapsed time for a busy, multi–threaded program.
timeprints 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.