12 out of 27 rated this helpful - Rate this topic

QueryPerformanceFrequency function

Applies to: desktop apps | Metro style apps

Retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.

Syntax

BOOL WINAPI QueryPerformanceFrequency(
  __out  LARGE_INTEGER *lpFrequency
);

Parameters

lpFrequency [out]

Type: LARGE_INTEGER*

A pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.

Return value

Type:

Type: BOOL

If the installed hardware supports a high-resolution performance counter, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. For example, if the installed hardware does not support a high-resolution performance counter, the function fails.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Reference
QueryPerformanceCounter
Conceptual
Timers

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Not related to CPU frequency in general
The high frequency counter need not be tied to the CPU frequency at all. It will only resemble the CPU frequency is the system actually uses the TSC (TimeStampCounter) underneath. As the TSC is generally unreliable on multi-core systems it tends not to be used. When the TSC is not used the ACPI Power Management Timer (pmtimer) may be used. You can tell if your system uses the ACPI PMT by checking if QueryPerformanceFrequency returns the signature value of 3,579,545 (ie 3.57MHz). If you see a value around 1.19Mhz then your system is using the old 8245 PIT chip. Otherwise you should see a value approximately that of your CPU frequency (modulo any speed throttling or power-management that might be in effect.) If you have a newer system with an invariant TSC (ie constant frequency TSC) then that is the frequency that will be returned (if Windows uses it). Again this is not necessarily the CPU frequency.
This function is not for obtain CPU frequency
This function NOT obtain the CPU frequency (or CPU speed). This function is to get the frequency of the high resolution timer counter. Timer counter value is obtained with QueryPerformanceTimer()
"Frequency"
Technically this article, and the community comments are correct, this function does query the frequency of the CPU. but only in so far as that 99.9% of current CPU's available operate at the same frequency as the Performance timer component within. However, you must remember you are querying for the frequency of this timer, not the frequency of the actual CPU.

I myself (on an Intel Celeron Mobile based machine) have noted on occasion that the CPU frequency reported in tools such as CPU-Z is different to the frequency reported by this function call. This is especially true when using Intel Speed Step, or when the BIOS has been set to use CPUTHRM settings to throttle down the CPU when overheating.

In these latter occasions is common to see a higher return from "QueryPerformanceFrequency" than one can see reported by the CPU. Skewing any timing performed in a high performance loop.
retrieve CPU speed
Apparently this function can be used to retrieve the processor speed,is it correct ?

arabcoder
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool QueryPerformanceFrequency(out long lpFrequency);
vb.net syntax
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function QueryPerformanceFrequency(<Out> ByRef lpFrequency As Long) As Boolean
End Function