Skip to content

Instantly share code, notes, and snippets.

@gszauer
Created June 6, 2013 00:35
Show Gist options
  • Save gszauer/5718465 to your computer and use it in GitHub Desktop.
Save gszauer/5718465 to your computer and use it in GitHub Desktop.
/************************************************************************************
* High Resolution Windows Timer
* -----------------------------
* code by : bobby anguelov - banguelov@cs.up.ac.za
* downloaded from : takinginitiative.wordpress.org
*
* code is free for use in whatever way you want, however if you work for a game
* development firm you are obliged to offer me a job :P (haha i wish)
************************************************************************************/
#ifndef HRTIMER
#define HRTIMER
#include <windows.h>
class HRTimer
{
private:
LARGE_INTEGER start;
LARGE_INTEGER stop;
LARGE_INTEGER frequency;
LARGE_INTEGER timeElapsed;
public:
HRTimer()
{
//get CPU frequency
QueryPerformanceFrequency( &frequency );
}
void startTimer()
{
//store initial value
QueryPerformanceCounter( &start ) ;
}
void stopTimer()
{
//store end value
QueryPerformanceCounter( &stop ) ;
}
double getElapsedTime()
{
//get elapsed time
timeElapsed.QuadPart = stop.QuadPart - start.QuadPart;
double elapsedS = (double)timeElapsed.QuadPart / (double)frequency.QuadPart;
//return elapsed time in seconds
return elapsedS;
}
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment