加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在C中经过的时间

发布时间:2020-12-16 10:19:09 所属栏目:百科 来源:网络整理
导读:#include time.h time_t start,end; time (start);//code heretime (end); double dif = difftime (end,start); printf ("Elasped time is %.2lf seconds.",dif ); 我的开始和结束时间都是0.000.我不理解错误的来源. 最好还是使用time(start)和time(end)或st
#include <time.h> 
time_t start,end; 
time (&start);
//code here
time (&end); 
double dif = difftime (end,start); 
printf ("Elasped time is %.2lf seconds.",dif );

我的开始和结束时间都是0.000.我不理解错误的来源.

最好还是使用time(start)和time(end)或start = clock()和end = clock()来计算经过的时间.

解决方法

在大多数(几乎所有?)系统中,time()只有一秒的粒度,因此任何亚秒的时间长度都无法用它来测量.如果您使用的是Unix,请尝试使用gettimeofday.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读