How to gracefully calculate the running time of programs by linux
Editor to share with you how elegant linux computing program running time, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Elegant computing program run time
Under Linux, you can easily get the run time of the program through the time command:
$time. / test
Real 0m1.003s
User 0m0.000s
Sys 0m0.000s
As you can see, the running time of the program is 1.003s. Careful students will see that real doesn't seem to be equal to user + sys, and it's much bigger than that. What's going on?
Let's first explain the meaning of these three parameters:
Real: clock time, that is, time spent from program execution to completion; user: time spent by cpu in user space during operation; sys: time spent by cpu in kernel space during operation
Because user and sys only count the time consumed by cpu, the call to sleep will block during the run of the program, or they may wait for the network or disk IO, which will consume a lot of time. So for similar cases, the value of real will be greater than the sum of the other two.
In addition, you will also encounter scenarios where real is much smaller than user + sys. What the heck is this?
This is easier to understand. If the program is parallel on multiple cpu, then the statistical time of user and sys is multiple cpu time, and the actual time consumed real is likely to be less than the sum of the other two.
These are all the contents of the article "how to elegantly calculate the running time of programs in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!