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.