Fixed up the improved StopWatch for DAPNET use.

This commit is contained in:
Jonathan Naylor 2018-07-04 22:18:48 +01:00
parent 31aabe1ddf
commit 79cf0678a9
2 changed files with 9 additions and 10 deletions

View file

@ -21,8 +21,8 @@
#if defined(_WIN32) || defined(_WIN64)
CStopWatch::CStopWatch() :
m_frequencyMS(),
m_frequencyS(),
m_frequencyMS(),
m_start()
{
::QueryPerformanceFrequency(&m_frequencyS);
@ -63,6 +63,7 @@ unsigned int CStopWatch::elapsed()
#else
#include <cstdio>
#include <ctime>
CStopWatch::CStopWatch() :
m_start()
@ -83,21 +84,19 @@ unsigned long long CStopWatch::time() const
unsigned long CStopWatch::start()
{
::gettimeofday(&m_start, NULL);
::clock_gettime(CLOCK_MONOTONIC, &m_start);
return m_start.tv_usec;
return m_start.tv_sec * 1000UL + m_start.tv_nsec / 1000000UL;
}
unsigned int CStopWatch::elapsed()
{
struct timeval now;
::gettimeofday(&now, NULL);
struct timespec now;
::clock_gettime(CLOCK_MONOTONIC, &now);
unsigned int elapsed = (now.tv_sec - m_start.tv_sec) * 1000U;
elapsed += now.tv_usec / 1000U;
elapsed -= m_start.tv_usec / 1000U;
int offset = ((now.tv_sec - m_start.tv_sec) * 1000000000UL + now.tv_nsec - m_start.tv_nsec ) / 1000000UL;
return elapsed;
return (unsigned int)offset;
}
#endif

View file

@ -42,7 +42,7 @@ private:
LARGE_INTEGER m_frequencyMS;
LARGE_INTEGER m_start;
#else
struct timeval m_start;
struct timespec m_start;
#endif
};