$ time foo
real 0m0.003s
user 0m0.000s
sys 0m0.004s
$
What do 'real', 'user' and 'sys' mean in the output of time?
Which one is meaningful when benchmarking my app?
Join Stack Overflow to learn, share knowledge, and build your career.
What do 'real', 'user' and 'sys' mean in the output of time? Which one is meaningful when benchmarking my app? |
||||
|
Real, User and Sys process time statistics One of these things is not like the other. Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process.
Origins of the statistics reported by The statistics reported by On a multi-processor machine, a multi-threaded process or a process forking children could have an elapsed time smaller than the total CPU time - as different threads or processes may run in parallel. Also, the time statistics reported come from different origins, so times recorded for very short running tasks may be subject to rounding errors, as the example given by the original poster shows. A brief primer on Kernel vs. User mode On Unix, or any protected-memory operating system, 'Kernel' or 'Supervisor' mode refers to a privileged mode that the CPU can operate in. Certain privileged actions that could affect security or stability can only be done when the CPU is operating in this mode; these actions are not available to application code. An example of such an action might be manipulation of the MMU to gain access to the address space of another process. Normally, user-mode code cannot do this (with good reason), although it can request shared memory from the kernel, which could be read or written by more than one process. In this case, the shared memory is explicitly requested from the kernel through a secure mechanism and both processes have to explicitly attach to it in order to use it. The privileged mode is usually referred to as 'kernel' mode because the kernel is executed by the CPU running in this mode. In order to switch to kernel mode you have to issue a specific instruction (often called a trap) that switches the CPU to running in kernel mode and runs code from a specific location held in a jump table. For security reasons, you cannot switch to kernel mode and execute arbitrary code - the traps are managed through a table of addresses that cannot be written to unless the CPU is running in supervisor mode. You trap with an explicit trap number and the address is looked up in the jump table; the kernel has a finite number of controlled entry points. The 'system' calls in the C library (particularly those described in Section 2 of the man pages) have a user-mode component, which is what you actually call from your C program. Behind the scenes, they may issue one or more system calls to the kernel to do specific services such as I/O, but they still also have code running in user-mode. It is also quite possible to directly issue a trap to kernel mode from any user space code if desired, although you may need to write a snippet of assembly language to set up the registers correctly for the call. A page describing the system calls provided by the Linux kernel and the conventions for setting up registers can be found here. More about 'sys' There are things that your code cannot do from user mode - things like allocating memory or accessing hardware (HDD, network, etc.). These are under the supervision of the kernel, and it alone can do them. Some operations that you do (like |
|||||||||||||||||||||
|
|
To expand on the accepted answer, I just wanted to provide another reason why Keep in mind that
|
|||||||||||||||||||||
|
|
Real shows total turn-around time for a process; while User shows the execution time for user-defined instructions and Sys is for time for executing system calls! Real time includes the waiting time also (the waiting time for I/O etc.) |
|||
|
|
|
• real: The actual time spent in running the process from start to finish, as if it was measured by a human with a stopwatch • user: The cumulative time spent by all the CPUs during the computation • sys: The cumulative time spent by all the CPUs during system-related tasks such as memory allocation.
|
|||||||||
|
|
real - is the number of minutes you put on your status report for trying to understand 'time'. it's basically the sum of (user + (sys * brains)). user - is the amount of time you spent actually reading this blog. This does not include time that your brain is doing other things like managing your bosses interruption. sys - is the amount of time actually thinking and trying to understand what it says. If you had multiple brains, you could multitask and hopefully it would be faster. Remember to only include the time spent on this issue. Not time spent thinking about lunch or whatever. |
|||||||||||||||||||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
time, have it do something that will take at least a second. – Peter Cordes Nov 25 '17 at 0:01