60

I am trying to figure out the performance of my code, but I do not understand the output of the time command, Can anybody please explain what does time command output means.

The following is what I get:

time ./filereader 

real    0m0.193s
user    0m0.012s
sys 0m0.056s

What is real, user, sys?

Sébastien Le Callonnec
  • 26,254
  • 8
  • 67
  • 80
Avinash
  • 12,851
  • 32
  • 116
  • 186
  • 1
    See duplicate question for comprehensive answer: http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1 – Sébastien Le Callonnec Sep 21 '12 at 19:53
  • 1
    Possible duplicate of [What do 'real', 'user' and 'sys' mean in the output of time(1)?](https://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1) – awiebe Jul 07 '18 at 23:59

3 Answers3

66

From: http://zch051383471952.blogspot.com/2010/01/different-of-real-user-sys-time.html

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).
  • User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.
  • Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CPU time used by the process.
NinjaCat
  • 9,974
  • 9
  • 44
  • 64
16

'real' is the amount of clock time it took. If you were to time it with a stopwatch, that's what you'd get.

'user' is the amount of CPU time that the process itself used.

'sys' is the amount of CPU time that the kernel spent on behalf of the process.

zebediah49
  • 7,467
  • 1
  • 33
  • 50
  • 4
    `real` is not the amount of time a stop watch tells, at least from my observations. For example, last night I started a process, and this morning it reports `real 2376m6.172s`. In reality, less than twelve hours have elapsed. – feklee Jul 22 '15 at 09:46
  • @feklee can you explain what 'real' means in this case? – Animesh Kumar Nov 10 '22 at 07:12
0

If you are developing with C/C++ you should use gprof to profile your code, check http://www.cs.duke.edu/~ola/courses/programming/gprof.html .

João Pinto
  • 5,521
  • 5
  • 21
  • 35