Measuring amount of CPU time taken by a piece of code, in C on Unix/Linux

后端 未结 6 1019
旧时难觅i
旧时难觅i 2021-01-05 13:18

Can clock() be used as a dependable API to measure time taken by CPU to execute a snippet of code? When verified usng times() / clock(), both do not seem to measure the CPU

6条回答
  •  离开以前
    2021-01-05 13:46

    Resource usage of a process/thread is updated by the OS only periodically. It's entirely possible for a code snippet to complete before the next update thus producing zero resource usage diffs. Can't say anything about HP or AIX, would refer you to Solaris Performance and Tools book for Sun. For Linux you want to look at oprofile and newer perf tool. On the profiling side valgrind would be of much help.

提交回复
热议问题