Use gettimeofday on Linux for the StopWatch.
This commit is contained in:
parent
6004b086e3
commit
cbc165f22f
2 changed files with 12 additions and 16 deletions
|
@ -62,24 +62,20 @@ CStopWatch::~CStopWatch()
|
|||
|
||||
unsigned long CStopWatch::start()
|
||||
{
|
||||
::clock_gettime(CLOCK_MONOTONIC, &m_start);
|
||||
::gettimeofday(&m_start, NULL);
|
||||
|
||||
return m_start.tv_nsec;
|
||||
return m_start.tv_usec;
|
||||
}
|
||||
|
||||
unsigned int CStopWatch::elapsed()
|
||||
{
|
||||
timespec now;
|
||||
::clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
struct timeval now;
|
||||
::gettimeofday(&now, NULL);
|
||||
|
||||
if (m_start.tv_sec == now.tv_sec) {
|
||||
return (now.tv_nsec - m_start.tv_nsec) / 1000000U;
|
||||
} else {
|
||||
long temp = -m_start.tv_nsec / 1000000L;
|
||||
temp += (now.tv_sec - m_start.tv_sec) * 1000L;
|
||||
temp += now.tv_nsec / 1000000L;
|
||||
return temp;
|
||||
}
|
||||
unsigned long long a = m_start.tv_sec * 1000ULL + m_start.tv_usec / 1000ULL;
|
||||
unsigned long long b = now.tv_sec * 1000ULL + now.tv_usec / 1000ULL;
|
||||
|
||||
return (unsigned int)(b - a);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <ctime>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
class CStopWatch
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
LARGE_INTEGER m_frequency;
|
||||
LARGE_INTEGER m_start;
|
||||
#else
|
||||
timespec m_start;
|
||||
struct timeval m_start;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue