Study Notes of boost timer Library

Source: Internet
Author: User
Timer

 

Usage

 

 

# Include <boost/Timer. HPP> # include <iostream> using namespace STD; using namespace boost; int main () {timer t; // declare a timer object and start timing cout <"Max: "<t. elapsed_max ()/3600 <"H" <Endl; // The maximum measurable time, in the unit of hour cout <"Min:" <t. elapsed_min () <"S" <Endl; // measurable minimum time (accuracy), in seconds as the unit of cout <"now:" <t. elapsed () <"S" <Endl; // output the elapsed time (starting from the declared object) return 0 ;}


 


 

 

Suggestions

 

Suitable for most timing tasks with low requirements.

Timer is not suitable for high-precision time measurement tasks. Its accuracy depends on the operating system or compiler and is difficult to cross-platform. It is not suitable for long-span periods.

Measurement. In addition, it has been declared obsolete and may be removed from the boost library at some point in the future. It can only be manually controlled by programmers, just like

Convenient stopwatch.

 

 

Progress_timer

 

Usage

 

# Include <boost/progress. HPP> # include <iostream> using namespace STD; using namespace boost; int main () {progress_timer t; // declare a timer object and start timing cout <"now: "<t. elapsed () <"S" <Endl; // output time elapsed int I = 60000; while (I --) {Int J = 6000; while (j --);} // only return 0 ;}


 

 

 

Suggestions:

 

Progress_timer is inherited from timer and will automatically output the time during the destructor. Therefore, the preceding results may take two minutes. One is manual call and the other is manual call.

Is automatically output during the analysis.

 

To measure multiple times in a program, use curly braces {} to limit the life cycle of progress_timer:

{Boost: progress_timer T1; // doing something} // automatically outputs the time {boost: progress_timer T2; // doing something} // The Output Time is automatically generated during structure analysis}

Note:

Different from timer, progress_timer constructor progress_timer (STD: ostream & OS) allows

In the specified Io stream, the default value is STD: Out.

 

 

 

 

 

 

 


 

 

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.