Skip to content

Instantly share code, notes, and snippets.

@rdp rdp/gist:1153062
Created Aug 18, 2011

Embed
What would you like to do?
example use of QueryPerformanceCounter
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
You can’t perform that action at this time.