clock函数的奇怪表现
c4droid吧
全部回复
仅看楼主
level 11
才不是惠痴ₔ
楼主
如果使用光标while循环那里计时十秒很准,输出除以单秒时间输出10,如果调用那个扫描目录的函数,运行了十秒,但输出只有0.3秒,
2021年10月23日 06点10分
1
level 11
才不是惠痴ₔ
楼主
2021年10月23日 07点10分
2
level 11
才不是惠痴ₔ
楼主
如果我把文件扫描函数换成延时函数,时间也对得上
2021年10月23日 07点10分
3
level 14
不知者来此
// 你需要 clock_gettime
unsigned int timeGet() {
struct timespec start;
clock_gettime(CLOCK_MONOTONIC, &start);
return start.tv_sec * 1000 + start.tv_nsec / CLOCKS_PER_SEC;
}
2021年10月24日 10点10分
4
才不是惠痴ₔ
哇,大佬又是你
2021年10月24日 13点10分
才不是惠痴ₔ
但是我很好奇为什么clock不行
2021年10月24日 13点10分
不知者来此
@才不是惠痴ₔ
我也不知道,我这只知道在多线程加速时和usleep时它变得不准。
2021年10月26日 16点10分
才不是惠痴ₔ
@不知者来此
我就用了DIR这个文件扫描的东西,应该不涉及多线程吧
2021年10月27日 10点10分
level 14
aaaaaaa421
可能是因为 clock 不计算系统调用的 CPU 时间,而只计算用户态 CPU 时间,这点你可以通过手动执行 time 指令查看你的程序的各项 CPU 时间来验证。
2021年11月02日 12点11分
5
1