Transferred from:Http://www.hudong.com/wiki/QueryPerformanceFrequency ()
Queryperformancefrequency ()-Basic Introduction
Type: WIN32API
Prototype: bool queryperformancefrequency (large_integer * lpfrequency );
Purpose: return the hardware-supported high-precision counter frequency.
Returned value: non-zero. Hardware supports high-precision counters. Zero, hardware does not support, and reading fails.
Queryperformancefrequency ()-Technical Features
High-precision timer for Win9x: queryperformancefrequency () and queryperformancecounter (), requiring computers to support high-precision timer on hardware.
The original form of the function is:
Bool queryperformancefrequency (large_integer * lpfrequency );
Bool queryperformancecounter (large_integer * lpcount );
the Data Type largeinteger can be an integer of 8 bytes, it can also be a joint structure of two 4-byte integers. The specific usage depends on whether the compiler supports 64-bit. This type is defined as follows:
typeef union _ large_integer
{< br> struct
{< br> DWORD lowpart;
long highpart;
};
Longlong quadpart;
}large_integer;
Call the queryperformancefrequency () function to obtain the clock frequency of the timer. Then, call queryperformancecounter () before and after the occurrence of an event that requires strict timing. the precise time of the event experience can be calculated using the difference in counting and clock frequency obtained twice. The exact duration method of the test function sleep (100:
Large_integer litmp;
Longlong qt1, qt2;
Double DFT, DFF, DFM;
Queryperformancefrequency (& litmp); // obtain the clock frequency
DFF = (double) litmp. quadpart;
Queryperformancecounter (& litmp); // obtain the Initial Value
Qt1 = litmp. quadpart; sleep (100 );
Queryperformancecounter (& litmp); // obtain the end value.
Qt2 = litmp. quadpart;
DFM = (double) (qt2-qt1 );
DFT = DFM/DFF; // obtain the corresponding time value
Note that the unit of result for DFT calculation is second.