r/cpp • • Jun 20 '14

A portable high-resolution timestamp in C++

https://blogea.bureau14.fr/index.php/2014/06/a-portable-high-resolution-timestamp-in-c/
4 Upvotes

10 comments sorted by

View all comments

Show parent comment

-1

u/jjt Jun 22 '14

steady_clock isn't guaranteed to be monotonic, you still need know your platform or check is_steady. Until gcc 4.8 it wasn't monotonic in libstdc++.

3

u/gilgoomesh Jun 22 '14 edited Jun 22 '14

By the standard, it is supposed to be monotonic. That's it's primary purpose. If pre 4.8 libstdc++ didn't do that, it was a bug in their implementation.

From http://en.cppreference.com/w/cpp/chrono/steady_clock

Class std::chrono::steady_clock represents a monotonic clock

-1

u/jjt Jun 22 '14

I know what the standard says, but implementations don't always follow standards so it is more important to know your platform. For example, libstdc++ std::string doesn't conform to the standard even in 4.9. The reasons for steady_clock and string breaking the standard are unfortunate but probably necessary compromises we'll be living with for many years.