"" Queryperformancefrequency ()

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.