Skip to content

Instantly share code, notes, and snippets.

@nkuln
Created October 20, 2011 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkuln/1300858 to your computer and use it in GitHub Desktop.
Save nkuln/1300858 to your computer and use it in GitHub Desktop.
Example for QueryPerformanceCounter to get current time in Windows C++
//
// PerfCounterTimer:
// To get current time in millisecond, use (1000.0 * GetCurrentTime() / GetFrequency()).
// Practically, you must cache value from GetFrequency() so that you don't need to
// re-query the frequency every time
//
#pragma once
#include <windows.h>
class PerfCounterTimer
{
public:
static LONGLONG GetCurrentCounter()
{
LARGE_INTEGER counter;
if(!::QueryPerformanceCounter(&counter))
return -1.0;
return counter.QuadPart;
}
static LONGLONG GetFrequency()
{
LARGE_INTEGER freq;
if(!::QueryPerformanceFrequency(&freq))
return -1.0;
return freq.QuadPart;
}
private:
PerfCounterTimer(void){}
~PerfCounterTimer(void){}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment