Created
June 6, 2013 00:35
-
-
Save gszauer/5718465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************************ | |
* 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