In the previous article, we learned a boost class for processing time. Today we will learn another class for processing time-progress_timer, which inherits from the Timer class, with the Timer class function, we can further improve its ease of use. Next we will describe the class with the code:
# Include <iostream> # include <boost/progress. HPP> int main () {boost: progress_timer pt1; STD: cout <pt1.elapsed _ max () <STD: Endl; STD :: cout <pt1.elapsed _ min () <STD: Endl; STD: cout <pt1.elapsed () <STD: Endl; {boost: progress_timer pt2 ;} return 0 ;}
Since it inherits from timer, various public methods of timer can also be used. When reading the code, you may have questions about the actual purpose of defining an instance pt2 at the end of the Code but not performing any operations on it? The answer is: yes, because progress_timer automatically starts timing during the construction, and outputs the result to the stream during the analysis, which is output by the output stream. Therefore, it is more convenient than timer, so we do not need to perform any operations, and everything is executed by itself. This block scope declaration method in the Code is also useful for testing multiple algorithms in the same code.
Finally, we need to note that the accuracy of progress_timer is not less than two digits after the decimal point. If you need more precision, You need to customize it.
Simple Application of boost library-processing of time and date (2)