Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to gracefully calculate the running time of programs by linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report