The documentation says:
"Returns the approximate processor time used by the process since the beginning of an implementation-defined era related to the program's execution. To convert result value to seconds divide it by CLOCKS_PER_SEC."
That's pretty vague. CLOCK_PER_SEC
is set to 10^6
and the approximate stands for poor resolution, not that the current clocks tick over 1000 faster and the results are rounded. That might be not a very technical term, but it is appropriate. The actual resolution everywhere I tested was about 100Hz = 0,01s. It's been like that for years. Note date here http://www.guyrutenberg.com/2007/09/10/resolution-problems-in-clock/.
Then the doc follows with: "On POSIX-compatible systems, clock_gettime with clock id CLOCK_PROCESS_CPUTIME_ID offers better resolution."
So:
It's CPU time only. But 2 threads = 2*CPU time. See the example on cppreference.
It is not suited for fine grain measurements at all, as explained above. You were on the verge of its accuracy.
IMO measuring wall-clock is the only sensible thing, but its a rather personal opinion. Especially with multithreaded applications and multiprocessing in general. Otherwise results of
system
+user
should be similar anyways.
EDIT: At 3. This of course holds for computational tasks. If your process uses sleep
or give up execution back to system, it might be more feasible measuring CPU time. Also regarding the comment that clock
resolution is erm... bad. It is, but to be fair one could argue you should not measure such short computations. IMO its too bad, but if you measure times over few seconds I guess its fine. I would personally use others available tools.