gpt4 book ai didi

c - C 中耗时

转载 作者:太空狗 更新时间:2023-10-29 15:14:24 25 4
gpt4 key购买 nike

#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

关于c - C 中耗时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6179419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com