1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-24 19:52:37 +01:00
rpcs3/Utilities/Timer.h

47 lines
1002 B
C
Raw Normal View History

#pragma once
class Timer
{
private:
bool stopped;
double startTimeInMicroSec;
double endTimeInMicroSec;
LARGE_INTEGER frequency;
LARGE_INTEGER startCycle;
LARGE_INTEGER endCycle;
public:
Timer()
{
QueryPerformanceFrequency(&frequency);
startCycle.QuadPart = 0;
endCycle.QuadPart = 0;
stopped = false;
startTimeInMicroSec = 0;
endTimeInMicroSec = 0;
}
void Start()
{
stopped = false;
QueryPerformanceCounter(&startCycle);
}
void Stop()
{
stopped = true;
QueryPerformanceCounter(&endCycle);
}
double GetElapsedTimeInSec(){return GetElapsedTimeInMicroSec() / 1000000.0;}
double GetElapsedTimeInMilliSec(){return GetElapsedTimeInMicroSec() / 1000.0;}
double GetElapsedTimeInMicroSec()
{
if(!stopped) QueryPerformanceCounter(&endCycle);
startTimeInMicroSec = startCycle.QuadPart * (1000000.0 / frequency.QuadPart);
endTimeInMicroSec = endCycle.QuadPart * (1000000.0 / frequency.QuadPart);
return endTimeInMicroSec - startTimeInMicroSec;
}
};