Processing of time and date is always a complicated problem, while processing of time and date in C ++ is also relatively simple, unlike Java and C #, the stream provides a class that is very convenient and easy to use. However, with the launch of boost, time processing has become more and more simple and convenient. Today we will learn some convenient processing methods:
First, let's take a look at a basic class for time processing in boost, which is also the base class of several subsequent classes-timer. timer class can measure the passage of time. Based on different platforms, it provides time control in milliseconds or even microseconds. We can also use it to make a very simple timer. below, we use code to explain the usage of Timer:
#include <iostream>#include <boost/timer.hpp>int main() { boost::timer t; std::cout << "Max timespan : " << t.elapsed_max() / 3600 << "h" << std::endl; std::cout << "Min timespan : " << t.elapsed_min() << "s" << std::endl; std::cout << "Time elapsed : " << t.elapsed() << std::endl; return 0;}
Generally, we only need to use the above three Timer class member methods. The function names also probably know their usefulness. They are: getting the maximum measurable time span, the Unit is hours. The minimum time span that can be measured is measured in seconds. It should be noted that the starting time of the elapsed time is when the timer instance is constructed, not when the program starts to run!
Timer class is more than enough for short-term processing, because its maximum time span is several hundred hours, that is, we should use it to test the running time of some algorithms. If the processing time is in the unit of day, month, and year, you cannot continue to use the Timer class. Let's talk about the specific usage!
Simple use of the boost library-processing of time and date (1)