Time

From LQWiki
Jump to navigation Jump to search

This article is about the command time that is used to find out how long it takes for a command to run. If you are looking for a command that lets you see and change the current system date and time, see dAte.

Under bash, the time functionality is triggered by inserting the "time" key word before a command ( or commands in case of pipelines ). That works as follows:

$ time ls -R > /dev/null

yields the output

real    0m0.775s
user    0m0.200s
sys     0m0.256s

where

real is the actual time that the program took to execute, user is the number of CPU-seconds spent in user mode, and sys is the number of CPU-seconds spent in kernel mode.

It should be noted that real time will vary according to what other processes are running concurrent with the program being timed; this should be taken into account when benchmarking programs for optimization purposes.

The GNU implementation of time allows the use of the -f option, which allows the display of a number of other pieces of useful information. See man time for details.

When attempting to run the GNU implementation of time under bash, if you simply type "time" then it will be interpreted as the "time" builtIn. To explicitly tell bash to interpret time as a command you can :

  • Type "command time" instead.
  • Specify the full path to the command.

The builtin "times" gives the same kind of information as time but regarding all the processes run from the shell so far.