Overhead of time command in unix Overhead of time command in unix unix unix

Overhead of time command in unix


The overhead is fixed and, based on the source code, is only due to the fact that an extra process is being started (the time process itself), introducing a small amount of extra processing (a). Normally, the shell would start your program but, in this case, the shell starts time and time starts your process (with a fork).

This extra processing involves:

  • argument processing.
  • the time taken to fork and exec the child.

While the process being measured is running, time itself is simply waiting for it to exit (with a wait call) so has no impact on the process.

So, while the start-up time for the time process is actually included in the measurements, these will only be significant for very short processes. If your process runs for an appreciable amount of time, the overhead of time is irrelevant.

As to what I mean by appreciable, you can see the effect time has by running it with a very fast executable, and also see if it has any appreciable increase in overhead for longer-running processes:

pax> time sleep 0real    0m0.001suser    0m0.000ssys     0m0.000spax> time sleep 1real    0m1.001suser    0m0.000ssys     0m0.000spax> time sleep 10real    0m10.001suser    0m0.000ssys     0m0.004spax> time sleep 100real    1m40.001suser    0m0.000ssys     0m0.000s

In other words, hardly any effect at all.

Now, since you're only likely to be timing processes if they're long-running (it's hard to care whether a single process takes one or two milliseconds unless you're running it many times in succession, in which case there are better ways to increase performance), the fixed overhead of time gets less and less important.


(a): And, if you're using a shell with time built in (such as bash with its time reserved word), even that small overhead disappears.


Overhead of time should be fairly constant regardless of the program being timed. All it has to do is take a timestamp, run the program, take another timestamp and output a result.

In terms of accuracy etc: the shorter the program you are running is, the more impact time will have on it. e.g. time on "Hello World" is probably not going to give you good results. time on something that runs for a decent period will be very accurate since time's overhead will be well down in the noise.