SkTime updates
1) Use steady_clock instead of high_resolution_clock. If we don't have a
guarantee of monotonicity, it's pretty much useless for timing things.
2) Implement Mac/iOS with <chrono> too. This was waiting on C++11 library support.
Both high_resolution_clock and steady_clock are (still) busted on MSVC 2013,
so no change there.
BUG=skia:
Review URL: https://codereview.chromium.org/1521293002
diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp
index 86a0685..16f6616 100644
--- a/src/core/SkTime.cpp
+++ b/src/core/SkTime.cpp
@@ -36,24 +36,13 @@
return new double(1e6 / khz.QuadPart);
});
}
-#elif defined(__MACH__)
- // TODO: fold into std::chrono when available?
- #include <mach/mach_time.h>
- SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick);
- double SkTime::GetNSecs() {
- uint64_t ticks = mach_absolute_time();
- return ticks * *ns_per_tick.get([]{
- mach_timebase_info_data_t timebase;
- (void)mach_timebase_info(&timebase);
- return new double(timebase.numer * 1.0 / timebase.denom);
- });
- }
#else
- // This std::chrono code looks great on Linux and Android,
- // but MSVC 2013 returned mostly garbage (0ns times, etc).
+ // This std::chrono code looks great on Linux, Mac, and Android,
+ // but MSVC 2013 returns mostly garbage (0ns times, etc).
+ // This is ostensibly fixed in MSVC 2015.
#include <chrono>
double SkTime::GetNSecs() {
- auto now = std::chrono::high_resolution_clock::now();
+ auto now = std::chrono::steady_clock::now();
std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
return ns.count();
}