开发者

Puzzling output of the time command

开发者 https://www.devze.com 2023-01-21 14:23 出处:网络
I am trying to benchmark the run time of one of my scripts. I get following output #time ./foo.py real0m37.883s

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号