/****************************************************************************** * Filename: HighResTimer.cpp * Date: 12/06/2010 * Mod. Date: 03/21/2018 * Author: Joseph R. Pollack * Purpose: A high resolution timer suitable for profiling code. This new * version has stripped out the game specific functionality and * does not include windows.h in the header. ******************************************************************************/ #include "HighResTimer.h" #define WIN32_LEAN_AND_MEAN #include namespace Lunarium { HighResTimer::HighResTimer() { Initialize(); } void HighResTimer::Initialize() { mStartTime = 0; LARGE_INTEGER tickFreq; QueryPerformanceFrequency(&tickFreq); mTickFrequency = tickFreq.QuadPart; } // Starts or re-starts the timer. void HighResTimer::Reset() { LARGE_INTEGER tickStart; QueryPerformanceCounter(&tickStart); mStartTime = tickStart.QuadPart; } // Returns the amount of time in microseconds since the last Reset() call. int64_t HighResTimer::GetElapsedTime() { LARGE_INTEGER ticks; QueryPerformanceCounter(&ticks); int64_t elapsedMicro = ticks.QuadPart - mStartTime; elapsedMicro *= mcMils; elapsedMicro /= mTickFrequency; return elapsedMicro; } double HighResTimer::GetElapsedSeconds() { int64_t emicro = GetElapsedTime(); double dmicro = ((double)emicro); double dmcMils = ((double)mcMils); double seconds = dmicro / dmcMils; return seconds; } }