#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
反而。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)