The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter.
Syntax
BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount );
Parameters
lpPerformanceCount [out] Pointer to a variable that receives the current performance-counter value, in counts.
Return Value
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.
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.
Function Information
Minimum DLL Versionkernel32.dllHeaderDeclared in Winbase.h, include Windows.hImport libraryKernel32.libMinimum operating systems Windows 95, Windows NT 3.1UnicodeImplemented as Unicode version.
See Also
Timers Overview, QueryPerformanceFrequency
<DllImport("kernel32.dll", SetLastError:=True)> _ Public Shared Function QueryPerformanceCounter(<Out> ByRef lpPerformanceCount As Long) As Boolean End Function
[DllImport("kernel32.dll", SetLastError=true)] public static extern bool QueryPerformanceCounter(out long lpPerformanceCount);
HRTimer(void)
double getFrequency(void);void startTimer(void) ;double stopTimer(void);
LARGE_INTEGER start;LARGE_INTEGER stop;double frequency;//..
LARGE_INTEGER proc_freq; if (!::QueryPerformanceFrequency(&proc_freq)) throw Exception(TEXT("QueryPerformanceFrequency() failed")); return proc_freq.QuadPart;
DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0); ::QueryPerformanceCounter(&start); ::SetThreadAffinityMask(::GetCurrentThread(), oldmask);
DWORD_PTR oldmask = ::SetThreadAffinityMask(::GetCurrentThread(), 0); ::QueryPerformanceCounter(&stop); ::SetThreadAffinityMask(::GetCurrentThread(), oldmask); return ((stop.QuadPart - start.QuadPart) * frequency);