C++: Timing in Linux (using clock()) is out of sync (due to OpenMP?)

user 0m45.735s

clock() measures CPU time the process used (as good as it can) per 7.27.2.1

The clock function returns the implementation’s best approximation to the processor time used by the program since the beginning of an implementation-defined era related only to the program invocation.

and not wall clock time. Thus clock() reporting a time close to the user time that time reports is normal and standard-conforming.

To measure elapsed time, if you can assume POSIX, using clock_gettime is probably the best option, the standard function time() can also be used for that, but is not very fine-grained.

Leave a Comment