Created
October 20, 2011 10:36
-
-
Save nkuln/1300858 to your computer and use it in GitHub Desktop.
Example for QueryPerformanceCounter to get current time in Windows C++
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
// | |
// 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