求C语言运行时间测试代码!

如题所述

#include<time.h>
#include<stdio.h>
#include<stdlib.h>
void main(void)
{
clock_t start,finish;
double duration;
start = clock();
//
//被测时间的随便什么东西
//
finish = clock();
duration = double(finish - start)/CLOCKS_PER_SEC;
printf("time used:%f ms\n\n",1000*duration);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-03
函数名: clock
功 能: 确定处理器时间
用 法: clock_t clock(void);
程序例:

#include <time.h>
#include <stdio.h>
#include <dos.h>

int main(void)
{
clock_t start, end;
start = clock();

delay(2000);

end = clock();
printf("The time was: %f\n", (end - start) / CLK_TCK);

return 0;
}
第2个回答  2012-04-03
clock();
你去google一下就懂了
相似回答