2015-07-11 10:01:06 -04:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2015-08-28 21:01:18 -04:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
2015-07-11 10:01:06 -04:00
|
|
|
#include "Timer.h"
|
|
|
|
|
2015-08-28 21:01:18 -04:00
|
|
|
#ifdef WIN32
|
|
|
|
|
2015-07-11 10:01:06 -04:00
|
|
|
Timer::Timer()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
if(!QueryPerformanceFrequency(&li)) {
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
_frequency = double(li.QuadPart) / 1000.0;
|
|
|
|
|
|
|
|
QueryPerformanceCounter(&li);
|
|
|
|
_start = li.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::Reset()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
QueryPerformanceCounter(&li);
|
|
|
|
_start = li.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Timer::GetElapsedMS()
|
|
|
|
{
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
QueryPerformanceCounter(&li);
|
|
|
|
return double(li.QuadPart - _start) / _frequency;
|
2015-07-21 18:18:20 -04:00
|
|
|
}
|
|
|
|
|
2015-08-28 21:01:18 -04:00
|
|
|
#else
|
|
|
|
|
|
|
|
Timer::Timer()
|
2015-07-21 18:18:20 -04:00
|
|
|
{
|
2015-08-28 21:01:18 -04:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timer::Reset()
|
|
|
|
{
|
|
|
|
timespec start;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
|
|
|
|
|
|
|
_start = start.tv_sec * 1000000000 + start.tv_nsec;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Timer::GetElapsedMS()
|
|
|
|
{
|
|
|
|
timespec end;
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
|
|
|
|
|
|
uint64_t currentTime = end.tv_sec * 1000000000 + end.tv_nsec;
|
|
|
|
|
|
|
|
return (double)(currentTime - _start) / 1000000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|