boost::timer demo

#include <iostream>
#include <boost/timer.hpp>		//timer的头文件
using namespace boost;			//打开boost名字空间

int main(int argc, char** argv)
{
	timer t;		//定义一个计时器对象,并开始计时
	/*可度量的最大时间,以小时为单位*/
	std::cout << "max timespan:" << t.elapsed_max() / 3600 << "h" << std::endl;
	/*可度量的最大时间,以小时为单位*/
	std::cout << "min timespan:" << t.elapsed_min() << std::endl;
	/*输出已经流逝的时间*/
	std::cout << "now time elapsed:" << t.elapsed() << "s" << std::endl;
	return 0;
}

 输出效果:

 注意:

  1. 不适合高精度的时间测量
  2. 精度依赖操作系统与编译器,不好做跨平台
  3. 不合适大跨度时间段的测量,因为有最大时间跨度,elapsed_max()可获取
原文地址:https://www.cnblogs.com/dilex/p/10562334.html