View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Time

From LQWiki

Jump to: navigation, search

The command time is used to find out how long it takes for a command to run.

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 ./process.pl > /dev/null

yields the output

real    0m12.755s
user 0m6.267s
sys 0m0.018s

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 or info 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" reserved word. To explicitly tell bash to interpret time as a command you can :

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

A side note about time not being a builtin :

"time" in bash is a key word and as such is part of the shell grammar, which governs how the shell must understand what is typed on the command line. In this case it tells bash to activate the time functionality for the next command.

You can tell "time" is a key word with "type time" which outputs "time is a shell keyword".

"builtin time" will also give you :
bash: builtin: time: not a shell builtin

On the other hand, "times" is indeed a builtin. It gives the same kind of information as time but regarding all the processes run from the shell so far.


Personal tools