Boost之时间处理(timer库)
来源:互联网 发布:打车软件数据库设计 编辑:程序博客网 时间:2024/06/13 02:19
timer库包含三个小组件,分别是计时器timer、progress_timer和进度
一. timer
timer是一个小型的计时器,提供毫秒级别的计时精度和操作函数
#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; //输出已经流逝的时间 return 0;}
二. progress_timer
progress_timer继承自timer,会在析构时自动输出时间,省去了timer手动调用elapsed()的工作。
#include <iostream>#include <sstream>#include <boost/progress.hpp>using namespace std;using namespace boost;int main(){ int i = 100000000; { boost::progress_timer t; while (i) --i; } //progress_timer会在这里析构,自动输出时间 i = 10000000; stringstream ss; { progress_timer t(ss); //progress_timer可以将时间转移到指定的IO流中 while (i) --i; } cout << ss.str(); return 0;}
三. progress_display
progress_display是一个独立的类,在构造后显示出一个类似图形化进度条的界面,用两行以字符的形式显示百分比进度。然而要注意的是,如果程序本身执行的操作也是向标准输出输出字符,那么progress_display的进度显示将会一片混乱。
#include <iostream>#include <fstream>#include <vector>#include <boost/progress.hpp>using namespace std;using namespace boost;int main(){ vector<string> v(1000000); ofstream fs("./test.txt"); progress_display pd(v.size()); for (auto& x : v) { fs << x << endl; ++pd; //更新进度显示 } return 0;}
0 0
- Boost之时间处理(timer库)
- boost库之时间处理(timer,progress_timer, progress_display)
- boost::timer之时间处理器
- boost学习之二(时间 timer库)
- Boost之日期时间处理(date_time库)
- Boost学习之Timer库
- boost::date_time之时间处理
- boost库学习之 timer库
- 初探boost之timer库学习笔记
- 浅尝boost之timer
- 浅尝boost之timer
- boost完全开发指南第2章-处理时间2(时间类timer)
- Boost之时间与日期处理
- boost. timer库
- Boost库学习----timer
- boost-timer库学习
- boost--timer库
- boost库-timer
- Mybits Demo
- Android开发教程(九)ProgressBar
- 4-1编程挑战
- Vijos-1243 生产产品 (DP单调队列优化)
- STL priority_queue优先队列容器学习记录
- Boost之时间处理(timer库)
- C++之cin.ignore, cin.peek, cin.putback
- 小记
- 数学建模系列- 解决Matlab读取Excel文件报错:Could not start Excel server for import问题
- 炒土豆丝
- 装饰者模式 详解
- RtlZeroMemory
- 使用CGLib实现动态代理
- 安装swftool过程报错记录