Running on Linux (uname says:)
Linux 2.6.32-431.29.2.el6.x86_64 #1 SMP Sun Jul 27 15:55:46 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
My tests show that clock_gettime calls with a clock id of CLOCK_MONOTONIC_COARSE are an order of magnitude faster than calls that use a clock id CLOCK_MONOTONIC.
Here's a sample output from a test run which called clock_gettime one million times in a tight loop and measured the lapsed time in milliseconds:
CLOCK_MONOTONIC lapse 795
CLOCK_MONOTONIC_COARSE lapse 27
This pleases me and makes the profiler results look better, however I was hoping that I could use std::chrono or boost::chrono for portability and standard conformance without sacrificing this speed. Unfortunately I haven't found any way to convince chrono (either one) to use CLOCK_MONOTONIC_COARSE when it's available. I tried chrono::steady_clock, but the results are comparable to the CLOCK_MONOTONIC values.
Is there a way to specify to chrono that you are willing to sacrifice precision for speed?
std::chrono::
clocks did you use? – 5gon12ederCLOCK_MONOTONIC_COARSE
, you can easily build your own custom chrono-style clock around it. You just need a fewtypedef
s, and anow()
function. – Howard Hinnantchrono.cc
in the GNU implementation and it only deals withCLOCK_REALTIME
andCLOCK_MONOTONIC
. There isn't even a macro provided to select the coarse clocks. – 5gon12eder