C + + high-precision calculation code run time (reprint)

Source: Internet
Author: User

Reprint: http://blog.csdn.net/rrrfff/article/details/6583410

1     //the QueryPerformanceFrequency () function should be called before timing to obtain the clock frequency of the internal timer of the machine.2     //then QueryPerformanceCounter () is called before and after the event that requires strict timing, and the exact time of the event can be calculated by using the difference between the counts and the clock frequency obtained two times .3     //High-precision timers for Win9x use: QueryPerformanceFrequency () and QueryPerformanceCounter () require the computer to support high-precision timers from hardware.4     //The data type Largeinteger can be either a 8-byte long Integer or a union structure of two 4-byte long integers, depending on whether the compiler supports 64-bit.5Large_integer Frequency = {0};6QueryPerformanceFrequency (&Frequency);7     DoubleF = (Double) Frequency.quadpart;8QueryPerformanceCounter (&Frequency);9Longlong I =Frequency.quadpart;Ten     { One         //Do sth here A     } -QueryPerformanceCounter (&Frequency); - CString result; theResult. Format (_t ("Result:%f"),Double(frequency.quadpart-i)/F); -MessageBox (NULL, result, _t ("Test Report"), MB_OK);

C + + high-precision calculation code run time (reprint)

Related Article

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.