CPU 中的时间比现实中花费的时间更快
Time spends in CPU faster than in reality
我想知道为什么我的整个应用程序运行时间少于 8 seconds
而从 clock_gettime
获得的时间是 19.3468 seconds
这是实际发生的时间的两倍多.问题出在哪里?
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_start);
... // many calculations
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_stop);
double time_diff=(time_stop.tv_sec-time_start.tv_sec+
(1e-9)*(time_stop.tv_nsec-time_start.tv_nsec);
更新:
我没有明确使用任何 OpenMP。
CLOCK_MONOTONIC 如果你想测量总运行时间,包括阻塞等待 IO 的时间,应该使用,但它也包括其他进程导致的减速在您的程序尝试 运行.
时进行安排
我想知道为什么我的整个应用程序运行时间少于 8 seconds
而从 clock_gettime
获得的时间是 19.3468 seconds
这是实际发生的时间的两倍多.问题出在哪里?
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_start);
... // many calculations
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time_stop);
double time_diff=(time_stop.tv_sec-time_start.tv_sec+
(1e-9)*(time_stop.tv_nsec-time_start.tv_nsec);
更新:
我没有明确使用任何 OpenMP。
CLOCK_MONOTONIC 如果你想测量总运行时间,包括阻塞等待 IO 的时间,应该使用,但它也包括其他进程导致的减速在您的程序尝试 运行.
时进行安排