I am wondering why my entire application runs in less than 8 seconds
while the time obtained from clock_gettime
is 19.3468 seconds
which is more than two times as much as what happens in reality. Where is the problem from?
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);
Update:
I am not using any OpenMP explicitly.
Advertisement
Answer
CLOCK_MONOTONIC should be used if you want to measure total elapsed time, including time spent blocked waiting for IO, but it will also include slowdowns caused by other processes getting scheduled while your program is trying to run.