#include <stdio.h>
#include <time.h>
int main() {
clock_t begin, end;
double cost;
//开始记录
begin = clock();
/*待测试程序段*/
end = clock();
cost = (double)(end - begin)/CLOCKS_PER_SEC;
printf("cost=%lf secs\n",cost);
return 0;
}
待测试程序段为
int i=0;
for(;i<1000000;i++);
时的运行结果: