[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Versions 3.2 and 4 Performance Tuning Guide

Using the time Command to Measure CPU Use

The time command is a simple but useful tool for understanding the performance characteristics of a single program. time reports the elapsed time from beginning to end of the program, the real time. It also reports the amount of CPU time used by the program. The CPU time is divided into user and sys . The user value is the time used by the program itself and any library subroutines it calls. The sys value is the time used by system calls invoked by the program (directly or indirectly).

The sum of user + sys is total direct CPU cost of executing the program. This does not include the CPU costs of parts of the kernel that can be said to run on behalf of the program, but which do not actually run on its thread. For example, the cost of stealing page frames to replace the page frames taken from the free list when the program started is not reported as part of the program's CPU consumption.

The difference between the real time and the total CPU time, that is:

   real - (user + sys)

is the sum of all of the factors that can delay the program, plus the program's own unattributed costs. In roughly the order of diminishing size, these factors may be:

In the following example, the program used in the preceding section has been compiled with -O3 to make it quicker. There is very little difference between the real (wall-clock) time required to run the program and the sum of its user and system CPU times. The program is getting all the time it wants--probably at the expense of other programs in the system.

$ time looper
real    0m3.58s
user    0m3.16s
sys     0m0.04s

In the next example, we run the program at a lower priority by adding 10 to its nice value. It takes almost twice as long to run, but other programs are getting a chance to do their work too:

$ time nice -10 looper
real    0m6.54s
user    0m3.17s
sys     0m0.03s

Note that we placed the nice command within the time command, rather that the reverse. If we had entered

$ nice -10 time looper

we would have gotten a different time command (/usr/bin/time) with a lower-precision report, rather than the version of time we have been using, which is built into ksh. If the time command comes first, you will get the built-in version, unless you specify the fully qualified name of /usr/bin/time. If time is invoked from another command, you will get /usr/bin/time.

time and timex Cautions

There are several considerations that you should take into account when using time or its variant timex:

[ Previous | Next | Contents | Glossary | Home | Search ]