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

后端 未结 6 1037
旧时难觅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 14:01

    you can use clock_t to get the number of CPU ticks since the program started.

    Or you can use the linux time command. eg: time [program] [arguments]

提交回复
热议问题