timer
timer已经定义就开始计时,elapsed方法返回经历的时间。timer能的计时是有限制的。elapsed_max方法可以显示最长计时时间,elapsed_min方法显示最短计时时间。restart方法表示重新开始计时。
#include <iostream>
#include <boost\timer.hpp>
using namespace boost;
using namespace std;
int main() {
timer t;
cout << "最大计时时间:" << t.elapsed_max() / 3600 << "小时" << endl;
cout << "最小计时时间:" << t.elapsed_min() << "秒" << endl;
cout << "当前耗时:" << t.elapsed() << "秒" << endl;
t.restart();
cout << "当前耗时:" << t.elapsed() << "秒" << endl;
return 0;
}
最大计时时间:596.523小时
最小计时时间:0.001秒
当前耗时:0.002秒
当前耗时:0秒
progress_timer
progress_timer扩展自timer,析构时自动打印消耗时间。
#include <iostream>
#include <boost\timer.hpp>
#include <boost\progress.hpp>
using namespace boost;
using namespace std;
int main() {
{
progress_timer pt;
int total = 0;
for (int i = 0;i <= 100;i++) {
total += i;
}
cout << total << endl;
}
return 0;
}
5050
0.00 s
progress_display
progress_display处理长时间的计时过程。可以限制处理的进度。
#include <iostream>
#include <boost\timer.hpp>
#include <boost\progress.hpp>
#include <Windows.h>
using namespace boost;
using namespace std;
int main() {
progress_display pd(100);
for (int i = 0;i < 100;i++) {
Sleep(100);
++pd;
}
return 0;
}
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
***************************************************