您的位置:首页 > 其它

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;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: