
Untitled
By: a guest on
May 5th, 2012 | syntax:
C++ | size: 0.62 KB | hits: 16 | expires: Never
#ifndef TIMER_H
#define TIMER_H
#include <windows.h>
class Timer
{
private:
__int64 initialTS, currentTS;
float secsPerCount;
public:
Timer()
{
__int64 countsPerSec = initialTS = currentTS = 0;
QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
if (countsPerSec == 0)
secsPerCount = 1.0f;
else
secsPerCount = 1.0f / (float)countsPerSec;
init();
}
void init()
{
QueryPerformanceCounter((LARGE_INTEGER*)&initialTS);
}
float diff()
{
QueryPerformanceCounter((LARGE_INTEGER*)¤tTS);
return ((float)currentTS - (float)initialTS)*secsPerCount;
}
};
#endif