C - 测量计算时间 [英] C - measuring computing time
本文介绍了C - 测量计算时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有什么简单的方法可以测量 C 中的计算时间?我在执行时尝试了时间效用,但我需要测量程序的特定部分.
is there any simple way how to measure computing time in C? I tried time utility when executed, but I need to measure specific part of a program.
谢谢
推荐答案
你可以使用
中的clock
函数和宏CLOCKS_PER_SEC
:
You can use the clock
function in <time.h>
along with the macro CLOCKS_PER_SEC
:
clock_t start = clock() ;
do_some_work() ;
clock_t end = clock() ;
double elapsed_time = (end-start)/(double)CLOCKS_PER_SEC ;
现在 elapsed_time
保存调用 do_some_work
所用的时间,以秒为单位.
Now elapsed_time
holds the time it took to call do_some_work
, in fractional seconds.
这篇关于C - 测量计算时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文