clock_t类:
int i = 100000000;
clock_t start,finish; //定义开始,结束变量
start = clock();//初始化
while( i-- );
finish = clock();//初始化结束时间
double duration = (double)(finish - start) / CLOCKS_PER_SEC;//转换浮点型
printf( "%lf seconds\n", duration );
说明:clock()函数调用占用cpu时间,效果不理想
2.
#include<sys/time.h> int
gettimeofday(struct timeval*tv,struct timezone *tz )
struct timeval{
long tv_sec;/*秒*/
long tv_usec;/*微妙*/
};
struct timezone{
int tz_minuteswest;/*和greenwich时间差*/
int tz_dsttime;
}
测试程序运行的时间
最新推荐文章于 2022-09-17 20:46:52 发布