读书人

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

发布时间: 2013-01-23 10:44:49 作者: rapoo

关于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.

读书人网 >C语言

热点推荐