Timer库

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、时间处理等具体看书吧,后续有时间再补充

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值