How to measure user/system cpu time for a piece of program?

In linux shell, using “time [executable file]” this command to review the cpu time of user/system.

$ time myprog
real 0m2.792s
user 0m0.099s
sys 0m0.200s

Let’s me explain them.

The real time means that it spends this time to run a program. As for single processor system.

The real time is less than user+sys time. Because in multiprocessor system. For example, if there are two cores, no system call, the user time is 2s for one core, assuming they are in totally concurrent. So the user time is 2*2 = 4s. But the real time is 2s.

Note: The concurrent means the real concurrent. In one CPU(On core), it will not happen that the real time is less than user+sys time.

Good Luck.

Share this article to your social media
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments