boost学习笔记(计时器)

7 篇文章 0 订阅

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%
|----|----|----|----|----|----|----|----|----|----|
***************************************************
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值