views:

25

answers:

1

I am trying to benchmark the run time of one of my scripts. I get following output

#time ./foo.py
real    0m37.883s
user    1m0.648s
sys     0m4.680s
#

Internally, foo spawns multiple other processes and waits till all of them die. From this thread and my earlier understanding of real, user and sys times, I had thought that real time would at the least be equal to user time. This is because real time is all the time elapsed from start till the end (also includes time slices used by other processes). Whereas user time just consists of CPU time spent in the user-mode code within the process. So how is user time greater than real time here? Is it because somehow the user times of all the children processes are getting added?

+1  A: 

Real time is sometimes called wall-clock time. It is the time elapsed during the execution of the program. User time can be many times real time if the code is multithreaded as it sounds like your code is. Yes, it is basically adding up the user time for the threads; similar reasoning applies to system time.

seandavi