C ++ achieves high accuracy of computing program running time

Source: Internet
Author: User

ProgramChange from http://zhidao.baidu.com/question/57378776.html

Other reference http://www.vckbase.com/document/viewdoc? Id = 1301

 

The queryperformancefrequency () and queryperformancecounter () functions should be used for scheduled operations with higher precision requirements. These two functions are precise time functions only for Windows 95 and later versions, and require computers to support accurate timers on hardware.

 

Example:

# Include <iostream> <br/> # include <windows. h> <br/> using namespace STD; </P> <p> void test () // Test Procedure <br/>{< br/> for (INT I = 0; I <1000; I ++) <br/> {<br/> for (Int J = 0; j <100; j ++) <br/> {<br/> printf ("% d, % d/N ", I, j); <br/>}</P> <p> int main (void) <br/>{< br/> large_integer begaintime; <br/> large_integer endtime; <br/> large_integer frequency; <br/> queryperformancefrequency (& frequency ); <br/> queryperformancecounter (& begaintime ); </P> <p> // The <SPAN class = 'wp _ keywordlink'> Code </span> to be tested is put here <br/> test (); </P> <p> queryperformancecounter (& endtime); </P> <p> // output running time (unit: S) <br/> cout <"running time (unit: S):" <(double) (endtime. quadpart-begaintime. quadpart)/frequency. quadpart <Endl; </P> <p> system ("pause"); <br/> return 0; <br/>}

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.