Created
August 18, 2011 01:13
-
-
Save rdp/1153062 to your computer and use it in GitHub Desktop.
example use of QueryPerformanceCounter
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
long double PCFreqMillis = 0.0; | |
// this call only needed once... | |
// who knows if this is useful or not, speed-wise... | |
void WarmupCounter() | |
{ | |
LARGE_INTEGER li; | |
BOOL ret = QueryPerformanceFrequency(&li); | |
assert(ret != 0); // only gets run in debug mode LODO | |
PCFreqMillis = (long double(li.QuadPart))/1000.0; | |
} | |
__int64 StartCounter() | |
{ | |
LARGE_INTEGER li; | |
QueryPerformanceCounter(&li); | |
return (__int64) li.QuadPart; | |
} | |
long double GetCounterSinceStartMillis(__int64 sinceThisTime) | |
{ | |
LARGE_INTEGER li; | |
QueryPerformanceCounter(&li); | |
assert(PCFreq!= 0.0); | |
return long double(li.QuadPart-sinceThisTime)/PCFreqMillis; //division kind of forces us to return a double of some sort... | |
} // LODO do I really need long double here? no really. | |
// use like | |
// __int64 start = StartCounter(); | |
// ... | |
// long double elapsed = GetCounterSinceStartMillis(start) | |
// printf("took %.020Lf ms", elapsed); | |
// or to deeply debug: printf("start %I64d end %I64d took %.020Lf ms", start, StartCounter(), elapsed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment