c 计算 语句 执行 时间

当然,你也可以用clock函数来计算你的机器运行一个循环或者处理其它事件到底花了多少时间:
 
#include “stdio.h”
#include “stdlib.h”
#include “time.h”
 
int main( void )
{
   long    i = 10000000L;
   clock_t start, finish;
   double  duration;
   /* 测量一个事件持续的时间*/
   printf"Time to do %ld empty loops is ", i );
   start = clock();
   while( i-- )      ;
   finish = clock();
   duration = (double)(finish - start) / CLOCKS_PER_SEC;
   printf"%f seconds ", duration );
   system("pause");
}
 
在笔者的机器上,运行结果如下:
 
Time to do 10000000 empty loops is 0.03000 seconds
原文地址:https://www.cnblogs.com/chunlifang-luck/p/3178978.html