time can be used to measure the execution time of a program or a shell script. After the program or shell script is executed, time writes the following times to standard error: real, user, sys.
real is the elapsed time during the invoked process and its child processes, i.e. the time between program call and program termination.
user is the time spent by the process or one of its child processes when executing user code. A process executes user code when it executes machine instructions from its own code segment.
sys is the time spent by the process or one of its child processes when executing system code. A process executes system code when it executes machine instructions from system calls.
The output format for time is hh:mm:ss.tt, where hh stands for hours, mm for minutes, ss for seconds, and tt for tenths of a second.
Syntax
time[ -p] prog[ arg...] |
Writes the results of the measurement to the standard error output.
Name of the program (or shell script) to be timed.
Optional arguments that may be passed to prog exactly as if prog were called without time. If time is called on a multiprocessor system, the sum of user and system time may be greater than real time. A figure of more than 100% for the apparent CPU load is the result of child processes being split between a number of processors. |
Exit status
Corresponds to the exit status of prog. |
1-125 | Error in time. |
126 | prog cannot be executed. |
127 | prog was not found. |
Variable
PATH Determine the search path that will be used to locate the utility to be invoked. |
Locale
The following environment variables affect the execution of time: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example
Measure the execution time of the ls command. The standard output of ls is redirected to the file list.
|
See also
times |