Boost库学习----timer
来源:互联网 发布:动物探测仪软件 编辑:程序博客网 时间:2024/06/07 00:41
1.timer是一个很实用的小工具,而且十分简单,源码也十分简洁,主要是使用了标准库中的std::clock()实现的
例子:
timer t;
.........
..........
cout<<"time elapsed"<<t.elapsed()<<"s"<<endl;
打印出从开始到结束的时间间隔,以秒为单位
timer源码十分简洁
class timer{ public: timer() { _start_time = std::clock(); } void restart() { _start_time = std::clock(); } double elapsed() const {return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } double elapsed_max() const { return (double((std::numeric_limits<std::clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC); } double elapsed_min() const { return double(1)/double(CLOCKS_PER_SEC); } private: std::clock_t _start_time;};
可以看到类中有个成员变量_start_time ,每次初始化一个该类对象时就把当前时钟的值赋给它以记录开始时间,想计算一段时间后时钟的间隔,只需调用elapsed(), elapsed()函数计算此刻时钟的值与_start_time差并除以CLOCKS_PER_SEC。其中CLOCKS_PER_SEC是ctime中定义的宏,表示一秒钟内时钟的滴答次数,为1000,也就是一秒钟时钟滴答计数为1000。
elapsed_min()函数返回能记录的最小时间间隔,也就是1毫秒。elapsed_max()返回能记录的最大时间间隔。
- Boost库学习----timer
- boost-timer库学习
- Boost学习之Timer库
- boost库学习之 timer库
- 初探boost之timer库学习笔记
- boost. timer库
- boost--timer库
- boost库-timer
- Boost----- timer库
- boost timer库使用
- boost--timer库笔记
- Boost库学习随记一 timer库示例:
- [BOOST]学习使用点滴-2-Timer库[by galphy]
- boost学习之二(时间 timer库)
- 【08】 Boost库学习笔记之定时器(Timer)
- 【Boost】boost::timer库用法与实例
- 【Boost】boost库中timer定时器
- 【Boost】boost::timer库用法与实例
- oracle小记之修改字符集解决中文乱码
- warning: ISO C forbids an empty translation unit [-pedantic]
- C/C++学习笔记(三)
- js 打印
- Highstock配置
- Boost库学习----timer
- CRtmpServer设置拉流
- [转]50个c/c++源代码网站
- android SensorManager简要分析
- wireshark 抓取本地回环数据包
- ASP.NET MVC 重点教程一周年版 第九回 HtmlHelper
- 为什么要BRC认证
- 一个人。我可以
- android安全漏洞(六) 抢先接收广播 - 内因篇之广播接收器注册流程