QueryPerformanceCounter function
Retrieves the current value of the high-resolution performance counter.
Syntax
BOOL WINAPI QueryPerformanceCounter( __out LARGE_INTEGER *lpPerformanceCount );
Parameters
- lpPerformanceCount [out]
-
Type: LARGE_INTEGER*
A pointer to a variable that receives the current performance-counter value, in counts.
Return value
Type: BOOL
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
On a multiprocessor computer, it should not matter which processor is called. However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function.
Requirements
|
Minimum supported client | Windows 2000 Professional |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- QueryPerformanceFrequency
- Conceptual
- Timers
Send comments about this topic to Microsoft
Build date: 9/7/2011
return ((stop.QuadPart - start.QuadPart) / frequency);
- 11/18/2009
- peter_ne
- 9/4/2011
- Stanley Roark
Does the count include time the system spends in sleep or hibernation?
Does the count have a drift with the system time returned GetSystemTimeAsFileTime() even without updating the system time?
=> Yes, refer to http://msdn.microsoft.com/en-us/magazine/cc163996.aspx
public:
HRTimer(void)
double getFrequency(void);private:
void startTimer(void) ;
double stopTimer(void);
LARGE_INTEGER start;}
LARGE_INTEGER stop;
double frequency;
//..
HRTimer::HRTimer(void)
: start(),{
stop(),
frequency()
frequency = this->GetFrequency();}
double HRTimer::GetFrequency(void)
{
LARGE_INTEGER proc_freq;}
if (!::QueryPerformanceFrequency(&proc_freq)) throw Exception(TEXT("QueryPerformanceFrequency() failed"));
return proc_freq.QuadPart;
void HRTimer::StartTimer(void)
{
DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);}
::QueryPerformanceCounter(&start);
::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
double HRTimer::StopTimer(void)
{
DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0);}
::QueryPerformanceCounter(&stop);
::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
return ((stop.QuadPart - start.QuadPart) / frequency);
// Shouldn't you divide by frequency instead of multiply?
//
// Yes, ideed I was. Old was: frequency = 1.0 / GetFrequency()
//
// Still, I think directly dividing is clearer, so I changed it.
- 6/4/2009
- MatiasFG
- 7/12/2010
- Thomas Lee
- 6/15/2010
- Glauber Lima
- 7/12/2010
- Thomas Lee
http://msdn.microsoft.com/en-us/library/ms686247(VS.85).aspx
- 10/5/2009
- dfields
- 10/5/2009
- Thomas Lee
