首页 > 系统服务 > 详细

001.linux下clock()检测程序运行时间

时间:2015-11-16 18:53:19      阅读:238      评论:0      收藏:0      [点我收藏+]
 1 #include <stdio.h>
 2 #include <time.h>
 3 
 4 int main()
 5 {
 6     int i;
 7     int k;
 8     clock_t start,end;  //clock_t类型实际上为long int类型(4字节)
 9     printf("%d\n",sizeof(long int));
10     start = clock();
11     printf("start:%d\n",start);
12     for(i=0; i<10000000; i++) ;
13     end = clock();
14     printf("end:%d\n",end);
15     printf("%.3fs\n",(double)(end-start)/CLOCKS_PER_SEC); //linux下CLOCKS_PER_SEC=1000000l
16 }

运行结果:

4
start:0
end:20000
0.020s

001.linux下clock()检测程序运行时间

原文:http://www.cnblogs.com/ruo-yu/p/4969462.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!