C++Boost库学习之timer库

目录

1.timer库概述
  ①命名空间timer
  ②计时器类中用到的格式
2.类cpu_timer
  ①类定义
  ②使用例子
3.类auto_cpu_timer
  ①类定义
  ②使用例子

1.timer库概述 ^

  timer是一个很小的库,提供简易的计时功能,对了解程序执行所需的时间在测试和生产环境中都很有用。

  旧版本的计时器已经被弃用了,取而代之的是是更符合当前boost实践的CPU计时器cpu_timer和auto_cpu_timer。所有组件都在命名空间timer中,如下:

 ①命名空间timer ^
//头文件:<boost/timer/timer.hpp>
namespace boost
{
  namespace timer
  {
    class cpu_timer;       
    class auto_cpu_timer;  

    //纳秒级别的类型
    typedef boost::int_least64_t nanosecond_type;
    //结构体,提供纳秒级别的经过时间,用户时间,系统时间
    struct cpu_times
    {
      nanosecond_type wall;
      nanosecond_type user;
      nanosecond_type system;

      void clear();
    };
    //默认精度为6
    const int default_places = 6;

    //将时间转化为指定精度,或指定精度与格式的字符串,单位为秒
    std::string format(const cpu_times& times, short places, const std::string& format); 
    std::string format(const cpu_times& times, short places = default_places); 
  }
}
 ②计时器类中用到的格式 ^
格式字符串 形式
%w times.wall
%u times.user
%s times.system
%t times.user + times.system
%p times.wall,times
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值