Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The meaning of real, user, and sys in output of Linux time command [duplicate]

Tags:

linux

time

$ time ./Test   real    0m2.906s user    0m2.887s sys     0m0.017s 

Here is the program code:

#include <iostream> #include <map>  void func_a() {     std::map<int, int> m;     for (unsigned int i = 0; i < 10000; i++) {         m.insert(std::pair<int, int>(i, i));     } }  void func_b() {     std::map<int, int> m;     for (unsigned int i = 0; i < 1000000; i++) {         m.insert(std::pair<int, int>(i, i));     } }  int main() {     func_a();     func_b();     return 0; } 
like image 994
2607 Avatar asked Apr 22 '12 04:04

2607


People also ask

What is real user and SYS in time?

Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process. Real is wall clock time - time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete).

What does the time command do in Linux?

time command in Linux is used to execute a command and prints a summary of real-time, user CPU time and system CPU time spent by executing a command when it terminates.

How does the time command function in operating system?

The time command is one such command. The time command is in no way related to the date command, which provides the system's date and time. Instead, it times a program or script's execution and tells you how long it took.


1 Answers

If you take a look at the manpage (man time), it states:

The time command runs the specified program command with the given arguments. When command finishes, time writes a message to standard output giving timing statistics about this program run. These statistics consist of (i) the elapsed real time between invocation and termination, (ii) the user CPU time (the sum of the tms_utime and tms_cutime values in a struct tms as returned by times(2)), and (iii) the system CPU time (the sum of the tms_stime and tms_cstime values in a struct tms as returned by times(2)).

Basically though, the user time is how long your program was running on the CPU, and the sys time was how long your program was waiting for the operating system to perform tasks for it. If you're interested in benchmarking, user + sys is a good time to use. real can be affected by other running processes, and is more inconsistent.

like image 92
LukeGT Avatar answered Sep 21 '22 02:09

LukeGT