Some notes from discussions with Vlad on how to simply measuring load balance of a program using PROCESS_CPUTIME and CLOCK_MONOTONIC.
We start with a background introduction
CLOCK_REALTIME reports the actual wall clock time.
CLOCK_MONOTONIC is for measuring relative real time. It advances at the same rate as the actual flow of time but it’s not subject to discontinuities from manual or automatic (NTP) adjustments to the system clock.
CLOCK_PROCESS_CPUTIME_ID is for measuring the amount of CPU time consumed by the process.
CLOCK_THREAD_CPUTIME_ID is for measuring the amount of CPU time consumed by the thread, but it’s not supported by Linux. glibc emulates it badly by simply returning the amount of CPU time consumed by the process since the moment the thread was created.
We can make a guess on how much parallel performance you get by dividing the CLOCK_PROCESS_CPUTIME / CLOCK_MONOTONIC time.