aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkTime.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2016-05-04 14:02:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-04 14:02:14 -0700
commitf2509381bdd9e712919418f7ebe831f974208154 (patch)
treed17a15c24a12d6c805ef04c938016c3e1a59f864 /src/core/SkTime.cpp
parentb37c68ad42ae7880e702649a01655165c7e12acc (diff)
Now we're on MSVC 2015, try using std::chrono for timing again.
2015's std::chrono::high_resolution_clock should have a precision equal to our old custom code. Tested this locally on Windows 10 and Mac (the two affected platforms). Long term SkTime::GetNSecs() can probably be phased out for direct <chrono> use. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1950173002 Review-Url: https://codereview.chromium.org/1950173002
Diffstat (limited to 'src/core/SkTime.cpp')
-rw-r--r--src/core/SkTime.cpp41
1 files changed, 6 insertions, 35 deletions
diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp
index ba8fe3e3a3..e89d5b9b3a 100644
--- a/src/core/SkTime.cpp
+++ b/src/core/SkTime.cpp
@@ -5,10 +5,10 @@
* found in the LICENSE file.
*/
-#include "SkOncePtr.h"
#include "SkString.h"
#include "SkTime.h"
#include "SkTypes.h"
+#include <chrono>
void SkTime::DateTime::toISO8601(SkString* dst) const {
if (dst) {
@@ -65,37 +65,8 @@ void SkTime::GetDateTime(DateTime* dt) {
}
#endif // SK_BUILD_FOR_WIN32
-#if defined(_MSC_VER)
- // TODO: try std::chrono again with MSVC 2015?
- #include <intrin.h>
- SK_DECLARE_STATIC_ONCE_PTR(double, ns_per_tick);
- double SkTime::GetNSecs() {
- uint64_t ticks = __rdtsc();
- return ticks * *ns_per_tick.get([]{
- LARGE_INTEGER khz; // The docs say this returns Hz, but it returns KHz.
- QueryPerformanceFrequency(&khz);
- 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).
- #include <chrono>
- double SkTime::GetNSecs() {
- auto now = std::chrono::high_resolution_clock::now();
- std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
- return ns.count();
- }
-#endif
+double SkTime::GetNSecs() {
+ auto now = std::chrono::high_resolution_clock::now();
+ std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
+ return ns.count();
+}