From 11ca4f9000ca678a0d3ab4754a0cac266f920a65 Mon Sep 17 00:00:00 2001 From: Person Date: Tue, 6 Jun 2017 20:13:30 -0700 Subject: [PATCH] 06/6/2017 --Bug fixes -Any measurement of time which was sub-millisecond was wrong. --- Source/Ember/EmberDefines.h | 8 ++++---- Source/Ember/Timing.h | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Source/Ember/EmberDefines.h b/Source/Ember/EmberDefines.h index 482ef71..bb144c4 100644 --- a/Source/Ember/EmberDefines.h +++ b/Source/Ember/EmberDefines.h @@ -70,16 +70,16 @@ namespace EmberNs #define FLOAT_MIN_TAN -FLOAT_MAX_TAN #define EMPTYFIELD -9999 typedef std::chrono::high_resolution_clock Clock; +typedef std::chrono::duration> DoubleMs; +typedef std::chrono::time_point DoubleMsTimePoint; +static inline DoubleMsTimePoint NowMsD() { return time_point_cast(Clock::now()); } +static inline size_t NowMs() { return duration_cast(Clock::now().time_since_epoch()).count(); } typedef uint et; typedef std::lock_guard rlg; /// /// Thin wrapper around getting the current time in milliseconds. /// -static inline size_t NowMs() -{ - return duration_cast(Clock::now().time_since_epoch()).count(); -} #ifndef byte typedef unsigned char byte; diff --git a/Source/Ember/Timing.h b/Source/Ember/Timing.h index 80b643d..373558f 100644 --- a/Source/Ember/Timing.h +++ b/Source/Ember/Timing.h @@ -35,7 +35,7 @@ public: /// The begin time cast to a double double Tic() { - m_BeginTime = Clock::now(); + m_BeginTime = NowMsD(); return BeginTime(); } @@ -47,7 +47,7 @@ public: /// The elapsed time in milliseconds as a double double Toc(const char* str = nullptr, bool fullString = false) { - m_EndTime = Clock::now(); + m_EndTime = NowMsD(); double ms = ElapsedTime(); if (str) @@ -76,8 +76,7 @@ public: /// The elapsed time in milliseconds as a double double ElapsedTime() const { - duration elapsed = duration_cast(m_EndTime - m_BeginTime); - return elapsed.count() * 1000.0; + return (m_EndTime - m_BeginTime).count(); } /// @@ -139,8 +138,8 @@ private: } int m_Precision;//How many digits after the decimal place to print for seconds. - time_point m_BeginTime;//The start of the timing, set with Tic(). - time_point m_EndTime;//The end of the timing, set with Toc(). + DoubleMsTimePoint m_BeginTime;//The start of the timing, set with Tic(). + DoubleMsTimePoint m_EndTime;//The end of the timing, set with Toc(). static bool m_TimingInit;//Whether the performance info has bee queried. static uint m_ProcessorCount;//The number of cores on the system, set in Init(). };