To use the command, simply precede any command by the word
time, such as:
$ time ls
When the command completes,
time will report how long it took to execute the
$ time host wikipedia.org wikipedia.org has address 126.96.36.199 0.000u 0.000s 0:00.17 0.0% 0+0k 0+0io 0pf+0w $
User time vs system time
The total CPU time is the combination of the amount of time the CPU or CPUs spent performing some action for a program and the amount of time they spent performing system calls for the kernel on the program's behalf. When a program loops through an array, it is accumulating user CPU time. Conversely, when a program executes a system call such as
fork, it is accumulating system CPU time.
Real time vs CPU time
The term "real time" in this context refers to elapsed wall-clock time, like using a stop watch. The total CPU time (user time + sys time) may be more or less than that value. Because a program may spend some time waiting and not executing at all (whether in user mode or system mode) the real time may be greater than the total CPU time. Because a program may fork children whose CPU times (both user and sys) are added to the values reported by the
time command, but on a multicore system these tasks are run in parallel, the total CPU time may be greater than the real time.
Method of operation
According to the source code of the GNU implementation of
time, most information shown by
time is derived from the
wait3 system call. On systems that do not have a
wait3 call that returns status information, the
times system call is used instead.
- The Single UNIX® Specification, Issue 7 from The Open Group : time a simple command – Commands & Utilities Reference,
- Linux Programmer's Manual – User Commands : time a simple command or give resource usage –
|This Unix-related article is a stub. You can help Wikipedia by expanding it.|