#include "Timer.h"
ProfilingTimer::ProfilingTimer() {
- elapsedSoFarInNS = 0;
- lastStart = 0;
isRunning = false;
+ elapsedSoFarInNS = 0;
+
#ifdef _WINDOWS
// This initializes the frequency of the ticks, which does not change.
- QueryPerformanceFrequency(&frequency)
+ LARGE_INTEGER frequencyInfo;
+ QueryPerformanceFrequency(&frequencyInfo);
+ frequency = frequencyInfo.QuadPart;
+#else
+ lastStart = 0;
#endif // _WINDOWS
}
QueryPerformanceCounter(&endTime);
// frequency is ticks per second, 1 sec = 1 000 000 000 ns
// ticks / (tics/sec) * (ns / sec) = ns
- elapsedSoFarInNS += (endTime - lastStart) / frequency * 1000000000;
+ elapsedSoFarInNS += (endTime.QuadPart - lastStart.QuadPart) / frequency * 1000000000;
#else
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
elapsedSoFarInNS += ts.tv_nsec - lastStart;
#endif // _WINDOWS
- lastStart = 0;
+ lastStart.QuadPart = 0;
isRunning = false;
}
void ProfilingTimer::Reset() {
// if running, stop
- isRunning = 0;
- lastStart = 0;
+ isRunning = false;
+ lastStart.QuadPart = 0;
}
double ProfilingTimer::GetElapsedSoFarInNS() const {
QueryPerformanceCounter(&curTime);
// frequency is ticks per second, 1 sec = 1 000 000 000 ns
// ticks / (tics/sec) * (ns / sec) = ns
- LARGE_INTEGER curElapsed = elapsedSoFarInNS + ( (curTime - lastStart) / frequency * 1000000000 );
+ LONG curElapsed = elapsedSoFarInNS + ( (curTime.QuadPart - lastStart.QuadPart) / frequency * 1000000000 );
#else
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
double ProfilingTimer::GetElapsedSoFarInS() const {
if (!isRunning) {
// then we just return the current total
- return (double) elapsedSoFarInNS / 1000000000;
+ return (double) elapsedSoFarInNS / 1000000000UL;
}
#ifdef _WINDOWS
QueryPerformanceCounter(&curTime);
// frequency is ticks per second, 1 sec = 1 000 000 000 ns
// ticks / (tics/sec) * (ns / sec) = ns
- LARGE_INTEGER curElapsed = elapsedSoFarInNS + ( (curTime - lastStart) / frequency * 1000000000 );
+ LONG curElapsed = elapsedSoFarInNS + ( (curTime.QuadPart - lastStart.QuadPart) / frequency * 1000000000UL );
#else
timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);