Introducing UNIX and Linux |
Processes and devicesOverview |
Timing a programIt's often useful to know how long it takes to run a command.
Perhaps you need to compare the speeds of different machines (if
you have access to more than one) in order to choose the fastest
machine. Perhaps you need to know if a program takes a long time to
run so that you can schedule it when you run it again at a quiet
time of day. The command A more concise output can be obtained by running
If the system is busy, the real time will be larger, since there
will be many users running processes, all of which demand their
fair share of processor time. However, for a particular command
(such as
You will see that the total time for the command to run was slightly over 5 seconds, but the amount of processing time - and thus the work the system had to do - was very small in comparison. This is to be expected, since sleep does nothing anyway. The times for the system and user are the actual processing time, and exclude any idle time when the relevant processes are not running, so that the real time will always be at least the sum of the user and system time. If you wish to time a complex command, which is not a single word with arguments, then a simple way to do it is to create a shell script containing the command and time the execution of that script. |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck