Getting getrusage() to measure system time in C

我的未来我决定 提交于 2019-11-29 09:47:50

You're misunderstanding the difference between "user" and "system" time. Your example code is executing primarily in user-mode (ie, running your application code) while you are measuring, but "system" time is a measure of time spent executing in kernel-mode (ie, processing system calls).

ru_stime is the correct field to measure system time. Your test application just happens not to accrue any such time between the two points you check.

You should use usage.ru_utime, which is user CPU time used, instead.

Use gprof. This will give give you the time taken by each function. Install gprof and use these flags for compilation -pg -fprofile-arcs -ftest-coverage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!