Get reliable monotonic time in c++(multiplatform)
boost, c++, time
Solution
I would use std::chrono::steady_clock. By description it is not influenced by wall clock/system time changes and is best suitable for measuring intervals.
Problem
I need a monotonic clock that can be used to calculate intervals. Requirements: - Must be monotonic, must not be influenced by the device time. - Must not reset during an application session.(Same epoch for all return values in a session) - Must represent real life seconds (not cpu seconds), must not be influenced by number of threads/processes running at that time. - Seconds resolution is sufficient. In my research I have found Candidates: - `std::clock()(ctime)` - Seems to use cpu seconds - `boost::chrono::steady_clock()` - Does it use cpu seconds? Can the epoch change during an application `session(launch-end)`? - Platform specific methods(`clock_gettime`, `mach_absolute_time`). Did you ever encounter such a problem and what solution did you choose? Is `steady_clock()` reliable multiplatform?