You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
C++
65 lines
1.5 KiB
C++
|
4 years ago
|
/******************************************************************************
|
||
|
|
* 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 <Windows.h>
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|