c++ - std::chrono::system_clock vs std::chrono::high_resolution_clock behavior -
consider following code snippet:
#include <chrono> #include <cassert> int main() { auto result1 = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now().time_since_epoch()); auto result2 = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()); assert((result2.count() - result1.count()) < 10); }
i expecting difference in counts between 2 values should minimal (ideally less second). vs2015, difference in count of order of billions of seconds. how possible?
the reason asserts because high_resolution_clock
allowed (and does) have different epoch system_clock
.
it de facto standard (not specified portable) system_clock
's epoch measuring time since 1970-01-01 00:00:00 utc, neglecting leap seconds.
there no de facto standard high_resolution_clock
. on gcc high_resolution_clock
typedef system_clock
, , on gcc platforms, you'll notice perfect synchronization. on vs , libc++ high_resolution_clock
typedef steady_clock
.
for me, epoch of steady_clock
whenever computer booted up.
here video tutorial <chrono>
. covers lots of issues, including one, , hour long.
Comments
Post a Comment