Timer库
概要:timer是一个很小的库,提供简易的度量时间和进度显示功能,可用于性能测试等需要计时的任务。
一、timer
1、用法
#include <iostream>
#include <boost/timer.hpp>
using namespace std;
using namespace boost;
int main()
{
timer t;
cout << "max timespan:" //可度量的最大时间,以小时为单位
<< t.elapsed_max() / 3600 << "h" << endl;
cout << "min timespan:" //可度量最小时间,以秒为单位
<< t.elapsed_min() << "s" << endl;
cout << "now time elapsed:"//输出已经流逝的时间
<< t.elapsed() << "s" << endl;
}
timer对象一旦声明,他的构造函数就“启动了计时“的工作,之后可以随时使用elapsed()函数简单测量自对象创建之后所流逝的时间,输出结果如下:
max timespan:5.1241e+09h
min timespan:1e-06s
now time elapsed:0.000141s
[Finished in 1.7s]
2、类摘要
class timer
{
public :
timer() {_start_time = clock();}
void restart() {_start_time = clock();}
double elapsed() const {return double(clock() - _start_time) / CLOCKS_PER_SEC;}
double elapsed_min() const {return double(1) / double(CLOCKS_PER_SEC);}
double elapsed_max() const {return (double((numeric_limites<clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC);}
private:
clock_t,_start_time;
};
3、progress_timer
#include <iostream>
#include <boost/timer.hpp>
#include <boost/progress.hpp>
using namespace std;
using namespace boost;
int main()
{
progress_timer pro_t;//声明progress_timer对象
cout << "max timespan:" //可度量的最大时间,以小时为单位
/*执行任务*/
cout << pro_t.elapsed() << endl;//输出流逝时间
}
4、时间处理等具体看书吧,后续有时间再补充