首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

关于C的clock()函数解决办法

2013-01-23 
关于C的clock()函数1 #include stdio.h2 #include time.h3 int main(void){4int i05clock_t start,e

关于C的clock()函数
  1 #include <stdio.h>
  2 #include <time.h>
  3 int main(void){
  4     int i=0;
  5     clock_t start,end;
  6     start=clock();
  7     while(i++<100000);
  8     end=clock();
  9     printf("%ld %ld %ld\n",start,(long)end,(end-start));
 10 } 
在linux下面跑的,程序输出结果怎么全是0呢。
[解决办法]
我回答的还有问题,你可以看看http://bbs.csdn.net/topics/100188430
还是执行时间太短了
[解决办法]
可能你的电脑太快乐,
多加几个0试试 
while(i++ < 100000000);

还有:
clock_t clock(void); 
Returns the processor clock time used since the beginning of an implementation-defined era (normally the beginning of the program). The returned value divided by CLOCKS_PER_SEC results in the number of seconds. If the value is unavailable, then -1 is returned. 

热点排行