Boost库学习随记一 timer库示例:
2014-03-27 10:07
274 查看
#include <boost/timer.hpp> #include <boost/progress.hpp> #include <iostream> #include <sstream> #include <fstream> #include <vector> #include "boost_test.h" using namespace std; using namespace boost; int main() { //######timer 处理示例,timer 以处理几百小时之内,对精确度不高的时间统计。 timer t; cout << "最大处理时间:" << t.elapsed_max() / 3600 << " h" << endl; cout << "最小处理时间:" << t.elapsed_min() << " s" << endl; cout << "逝去时间:" << t.elapsed() << " s" << endl; system("pause"); cout << "暂停逝去时间:" << t.elapsed() << " s" << endl; t.restart(); cout << "restart逝去时间:" << t.elapsed() << " s" << endl; system("pause"); cout << "暂停逝去时间:" << t.elapsed() << " s" << endl; //#######progress_timer继承了timer的全部能力,示例一 progress_timer tt; //逻辑处理部分以计算逝去的时间,如pause... system("pause"); //progress会在main函数结束时进行析构输出时间 cout << "progress_timer: " << tt.elapsed() << endl; //progress_timer 示例二 { progress_timer tt; }//progress会在这里析构,自动输出时间 //progress_timer 示例三 stringstream ss; { progress_timer tt(ss); cout << "ss: " << ss.str() << endl; } //######progress_display 可以在控制台上显示程序的执行进度,缺陷,无法把进度显示输出与程序的输出分离。 vector<string> v(100); ofstream fs("c:\\test.txt"); //输出示例一 //progress_display pd(v.size()); //输出示例二 progress_display pd(v.size(), cout, "%%%", "+++", "???"); vector<string>::iterator pos; for (pos = v.begin(); pos != v.end(); ++pos) { fs << *pos << endl; ++pd; } /*输出示例一 0% 10 20 30 40 50 60 70 80 90 100% |----|----|----|----|----|----|----|----|----|----| *************************************************** 输出示例二 %%%0% 10 20 30 40 50 60 70 80 90 100% +++|----|----|----|----|----|----|----|----|----|----| ???*************************************************** */ system("pause"); return 0; }
相关文章推荐
- Boost库学习随记二 date_time、time_duration、date_facet、time_facet、timer库示例等:
- boost库学习随记六:使用同步定时器、异步定时器、bind、成员函数回调处理、多线程的同步处理示例等
- 【08】 Boost库学习笔记之定时器(Timer)
- Boost库学习随记四 pool内存池使用示例:pool、object_pool、singleton_pool、pool_alloc内存池
- TimerTask代码示例[学习]
- Boost库学习----timer
- boost库学习随记六:使用同步定时器、异步定时器、bind、成员函数回调处理、多线程的同步处理示例等
- Boost库学习------progress_timer
- 【Spring-AOP-学习笔记-7】@Around增强处理简单示例
- 批处理学习--参数值获取方法示例
- STL学习之一:vector用法示例1
- Boost库学习笔记 1. Boost介绍和环境配置
- OSG学习:矩阵变换节点示例
- sparql学习sparql示例、dbpedia在线验证
- Activiti boundrytimer 和listen结合使用学习
- 1天学习1个类库 MKMapView Overlay示例
- CUBRID学习笔记 34 net参数化查询 cubrid教程示例
- 机器学习之主成分分析PCA及代码示例
- boost库下载、编译、示例、文档
- C#示例学习(二)-使用委托传值