i was wondering what is the overhead of using the time command in unix.
i know how to use it, but i want to know how much longer the command
$ time java HelloWorld
takes on a terminal, than the command
$ java HelloWorld
I am specifically interested in how this overhead varies with the time duration of the program that is running.
context::
I am using it to measure the time taken for a bunch of long running experiments written in Java.
The overhead is fixed and, based on the source code, is only due to the fact that an extra process is being started (the
timeprocess itself), introducing a small amount of extra processing (a). Normally, the shell would start your program but, in this case, the shell startstimeandtimestarts your process (with afork).This extra processing involves:
forkandexecthe child.While the process being measured is running,
timeitself is simply waiting for it to exit (with awaitcall) so has no impact on the process.So, while the start-up time for the
timeprocess 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 oftimeis irrelevant.As to what I mean by appreciable, you can see the effect
timehas by running it with a very fast executable, and also see if it has any appreciable increase in overhead for longer-running processes: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
timegets less and less important.(a): And, if you’re using a shell with
timebuilt in (such asbashwith itstimereserved word), even that small overhead disappears.