4 ms·
I was curious how linux's clock_gettime compared. I wrote a simple program that tried all the clock types documented in my manpage: https://gist.github.com/jepl
by jepler 2y ago
I was curious how linux's clock_gettime compared. I wrote a simple program that tried all the clock types documented in my manpage: https://gist.github.com/jepler/e37be8fc27d6fb77eb6e9746014db925 https://gist.github.com/jepler/e37be8fc27d6fb77eb6e9746014db...
My two handy systems were an i5-1235U running 6.1.0-20-amd64 and a Ryzen 7 3700X also running 6.1.0-20-amd64. The fastest method was 3.7ns/s call on the i5 and 4ns/call on the Ryzen (REALTIME_COARSE and MONOTONIC_COARSE were about the same). If a "non-coarse" timestamp is required, the time increases to about 20ns/call on ryzen, 12ns on i5. (realtime, tai, monotonic, boottime).
On the i5, if I force the benchmark to run on an efficiency core with taskset, times increase to 6.4ns and 19ns.
- jeffbee 2y agoYou can knock almost a third off that fastest time by building with `-static`. In something that is completely trivial like reading the clock via vDSO the indirect call overhead of dynamic libc linking becomes huge. `-static` eliminates one level of indirect calls. The indirect vDSO call remains, though. % ./clocktest | rg MONOTONIC_COARSE MONOTONIC_COARSE : 2.2ns percall