博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Boost】timer、progress_timer和progress_display
阅读量:6816 次
发布时间:2019-06-26

本文共 3873 字,大约阅读时间需要 12 分钟。

 

 

Table of Contents

1 timer

timer t; //声明一个timer类对象t,调用构造函数开始计时

timer t(t0); //调用默认的复制构造函数,t的流逝时间与t0相同
成员函数:

  1. elapsed() 流逝的时间
  2. elapsed_max() 计时器最大范围
  3. elapsed_min() 计时器最小范围
  4. restart() 重新开始计时

2 progress_timer

该类构造函数开始计时,析构函数则在适当的位置以适当的形式打印自构造函数调用开始到析构函数调用的时间。

3 progress_display

以进度条的形式显示进度:

 

0%   10   20   30   40   50   60   70   80   90   100%|----|----|----|----|----|----|----|----|----|----|************************************
progress_display( unsigned long expected_count,                  std::ostream& os,  // os is hint; implementation may ignore                  const std::string & s1 = "\n", //leading strings                  const std::string & s2 = "",                  const std::string & s3 = "" )

成员函数:

  1. count() 进度计数
  2. expected_count() 返回初始化该类对象的expected_count值
  3. restart(unsigned long expected_count) 中止当前进度条的显示,并重新赋值

文档中给的例子:

 

//  timer, job_timer, and progress_display sample program  -------------------////  Copyright Beman Dawes 1998.  Distributed under the Boost//  Software License, Version 1.0. (See accompanying file//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)//  See http://www.boost.org/libs/timer for documentation.//  Revision History//  12 Jan 01  Cut time to 1.0 secs to speed regression tests (Beman Dawes)//  25 Sep 99  added elapsed_min() and elapsed_max() reporting//  16 Jul 99  Second beta//   6 Jul 99  Initial boost version#include 
#include
#include
using boost::timer;using boost::progress_timer;using boost::progress_display;using std::cout;using std::endl;int main(){ timer t0; // used only for elapsed_max() and elapsed_min() cout << "timer::elapsed_min() reports " << t0.elapsed_min() << " seconds\n"; cout << "timer::elapsed_max() reports " << t0.elapsed_max() << " seconds, which is " << t0.elapsed_max()/3600.0 << " hours\n"; cout << "\nverify progress_display(0) doesn't divide by zero" << endl; progress_display zero( 0 ); // verify 0 doesn't divide by zero ++zero; long loops; timer loop_timer; const double time = 1.0; cout << "\ndetermine " << time << " second iteration count" << endl; for ( loops = 0; loops < LONG_MAX && loop_timer.elapsed() < time; ++loops ) {} cout << loops << " iterations"<< endl; long i; bool time_waster; // defeat [some] optimizers by storing result here progress_timer pt; timer t1; timer t4; timer t5; cout << "\nburn about " << time << " seconds" << endl; progress_display pd( loops ); for ( i = loops; i--; ) { time_waster = loop_timer.elapsed() < time; ++pd; } timer t2( t1 ); timer t3; t4 = t3; t5.restart(); cout << "\nburn about " << time << " seconds again" << endl; pd.restart( loops ); for ( i = loops; i--; ) { time_waster = loop_timer.elapsed() < time; ++pd; } if ( time_waster ) cout << ' '; // using time_waster quiets compiler warnings progress_display pd2( 50, cout, "\nLead string 1 ", "Lead string 2 ", "Lead string 3 " ); for ( ; pd2.count() < 50; ++pd2 ) {} cout << "\nt1 elapsed: " << t1.elapsed() << '\n'; cout << "t2 elapsed: " << t2.elapsed() << '\n'; cout << "t3 elapsed: " << t3.elapsed() << '\n'; cout << "t4 elapsed: " << t4.elapsed() << '\n'; cout << "t5 elapsed: " << t5.elapsed() << '\n'; cout << "t1 and t2 should report the same times (very approximately " << 2*time << " seconds).\n"; cout << "t3, t4 and t5 should report about the same times,\n"; cout << "and these should be about half the t1 and t2 times.\n"; cout << "The following elapsed time should be slightly greater than t1." << endl; return 0;} // main

Author: visaya fan

Date: 2012-04-30 00:22:18

HTML generated by org-mode 6.33x in emacs 23

转载于:https://www.cnblogs.com/visayafan/archive/2012/04/30/2476616.html

你可能感兴趣的文章
上网行为管理设备网关部署方式
查看>>
TCP协议与UDP协议的区别
查看>>
MySQL 忘记root密码解决办法
查看>>
路由器的4种配置模式
查看>>
时空大数据可视化之湖泊可视化简介(Lake Level Viewer)
查看>>
The reference to entity "characterEncoding" must end with the ';' delimiter
查看>>
意大利石油和天然气服务公司Saipem称遭到了来自印度的网络***
查看>>
zabbix 自定义端口监控 。
查看>>
软件定时器算法
查看>>
day1 01
查看>>
[MACOS] Mac上的抓包工具Charles
查看>>
电话机器人原来真的运用了人工智能的核心技术
查看>>
实现图片的轮播效果
查看>>
pt-archiver 数据删除、迁移工具使用
查看>>
下载网站地址
查看>>
桌面虚拟化浅谈
查看>>
我的友情链接
查看>>
将 TensorFlow 移植到 Android手机,实现物体识别、行人检测和图像风格迁移详细教程...
查看>>
Hyper-V 自动化支持技术
查看>>
VS2010启动调试时报“未能将脚本调试器附加到计算机”
查看>>