boost之progress_timer计时器

本文介绍了Boost库中的Progress_Timer计时器的使用方法。该计时器不仅具备基本计时功能,还能在对象析构时自动输出经过的时间,简化了代码。此外,还展示了如何将输出重定向到stringstream以便于进一步处理。
progress_timer计时器继承自timer,具有timer的全部能力。除此之外,它会在析构时自动输出时间,省去了timer调用elapsed()的工作。

#include "stdafx.h"
#include <boost/progress.hpp>

int main()
{
	boost::progress_timer t;  //声明对象开始计时
	int i = 10000000000;	  //操作
	while (i--);
    return 0;
}							  //退出作用域,调用析构函数,输出流逝的时间
输出结果是:

把progress_timer的输出转移到了stringstream中,它可以被转换为字符串供其他应用使用

#include <boost/progress.hpp>
#include <sstream>
int main()
{
	std::stringstream str;
	{
		boost::progress_timer t;  //声明对象开始计时
		int i = 10000000000;	  //操作
		while (i--);
		return 0;
	}	//退出作用域,调用析构函数,输出流逝的时间
	std::string temp = str.str();
	std::cout << temp << std::endl;
}							  
输出结果是:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值