06/6/2017

--Bug fixes
 -Any measurement of time which was sub-millisecond was wrong.
This commit is contained in:
Person 2017-06-06 20:13:30 -07:00
parent c194d708fd
commit 11ca4f9000
2 changed files with 9 additions and 10 deletions

View File

@ -70,16 +70,16 @@ namespace EmberNs
#define FLOAT_MIN_TAN -FLOAT_MAX_TAN #define FLOAT_MIN_TAN -FLOAT_MAX_TAN
#define EMPTYFIELD -9999 #define EMPTYFIELD -9999
typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::duration<double, std::ratio<1, 1000>> DoubleMs;
typedef std::chrono::time_point<Clock, DoubleMs> DoubleMsTimePoint;
static inline DoubleMsTimePoint NowMsD() { return time_point_cast<DoubleMs>(Clock::now()); }
static inline size_t NowMs() { return duration_cast<milliseconds>(Clock::now().time_since_epoch()).count(); }
typedef uint et; typedef uint et;
typedef std::lock_guard <std::recursive_mutex> rlg; typedef std::lock_guard <std::recursive_mutex> rlg;
/// <summary> /// <summary>
/// Thin wrapper around getting the current time in milliseconds. /// Thin wrapper around getting the current time in milliseconds.
/// </summary> /// </summary>
static inline size_t NowMs()
{
return duration_cast<milliseconds>(Clock::now().time_since_epoch()).count();
}
#ifndef byte #ifndef byte
typedef unsigned char byte; typedef unsigned char byte;

View File

@ -35,7 +35,7 @@ public:
/// <returns>The begin time cast to a double</returns> /// <returns>The begin time cast to a double</returns>
double Tic() double Tic()
{ {
m_BeginTime = Clock::now(); m_BeginTime = NowMsD();
return BeginTime(); return BeginTime();
} }
@ -47,7 +47,7 @@ public:
/// <returns>The elapsed time in milliseconds as a double</returns> /// <returns>The elapsed time in milliseconds as a double</returns>
double Toc(const char* str = nullptr, bool fullString = false) double Toc(const char* str = nullptr, bool fullString = false)
{ {
m_EndTime = Clock::now(); m_EndTime = NowMsD();
double ms = ElapsedTime(); double ms = ElapsedTime();
if (str) if (str)
@ -76,8 +76,7 @@ public:
/// <returns>The elapsed time in milliseconds as a double</returns> /// <returns>The elapsed time in milliseconds as a double</returns>
double ElapsedTime() const double ElapsedTime() const
{ {
duration<double> elapsed = duration_cast<milliseconds, Clock::rep, Clock::period>(m_EndTime - m_BeginTime); return (m_EndTime - m_BeginTime).count();
return elapsed.count() * 1000.0;
} }
/// <summary> /// <summary>
@ -139,8 +138,8 @@ private:
} }
int m_Precision;//How many digits after the decimal place to print for seconds. int m_Precision;//How many digits after the decimal place to print for seconds.
time_point<Clock> m_BeginTime;//The start of the timing, set with Tic(). DoubleMsTimePoint m_BeginTime;//The start of the timing, set with Tic().
time_point<Clock> m_EndTime;//The end of the timing, set with Toc(). DoubleMsTimePoint m_EndTime;//The end of the timing, set with Toc().
static bool m_TimingInit;//Whether the performance info has bee queried. 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(). static uint m_ProcessorCount;//The number of cores on the system, set in Init().
}; };