我的机器不能用CLOCK?

zansan 2007-11-13 10:33:21
#include <stdio.h>
#include <time.h>
main()
{
clock_t start;
clock_t end;
int i;
int j;
start=clock();
j=0;
for(i=0;i<1000000;i++){
j=j+i;
}
end=clock();
printf(" %x %x ",end,start);
return;
}
================================
上述代码想测试运行时间.出现奇怪的事.
用MYCPP,输出是"f 0"与"0 0"交替出现.
用djgpp,输出只是"0 0".
怎么回事?哪为大侠解救我于疑惑的泥潭.这好象不是C快的事.
...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
geniuscaobo 2007-11-13
  • 打赏
  • 举报
回复
1000000: out of range


#include <stdio.h>
#include <time.h>
main()
{
clock_t start;
clock_t end;
int i;
int j;
start=clock();
j=0;
for(i=0;i <1000;i++){
j=j+i;
}
delay(2000);
end=clock();
printf( " %x %x ",end , start);
return;
}

相隔的时间

#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;
}

weiym 2007-11-13
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <time.h>
#include <windows.h>
main()
{
clock_t start;
clock_t end;
int i;
int j;
start=clock();
j=0;
for(i=0;i <1000000;i++){
j=j+i;
}
Sleep(1000); //休息一秒
end=clock();
printf( " %x %x ",end,start);
return;
}
weiym 2007-11-13
  • 打赏
  • 举报
回复
就是C快的事

64,640

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧