boost::timer
来源:互联网 发布:python java c 比较 编辑:程序博客网 时间:2024/06/12 20:56
namespace boost {// timer -------------------------------------------------------------------//// A timer object measures elapsed time.// It is recommended that implementations measure wall clock rather than CPU// time since the intended use is performance measurement on systems where// total elapsed time is more important than just process or CPU time.// Warnings: The maximum measurable elapsed time may well be only 596.5+ hours// due to implementation limitations. The accuracy of timings depends on the// accuracy of timing information provided by the underlying platform, and// this varies a great deal from platform to platform.class timer{ public: timer() { _start_time = std::clock(); } // postcondition: elapsed()==0// timer( const timer& src ); // post: elapsed()==src.elapsed()// ~timer(){}// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed() void restart() { _start_time = std::clock(); } // post: elapsed()==0 double elapsed() const // return elapsed time in seconds { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } double elapsed_max() const // return estimated maximum value for elapsed() // Portability warning: elapsed_max() may return too high a value on systems // where std::clock_t overflows or resets at surprising values. { return (double((std::numeric_limits<std::clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC); } double elapsed_min() const // return minimum value for elapsed() { return double(1)/double(CLOCKS_PER_SEC); } private: std::clock_t _start_time;}; // timer} // namespace boost
timer计时器位于boost命名空间下,根据源码timer是对std::clock()的封装。查阅以下链接
http://en.cppreference.com/w/cpp/chrono/c/clock
对std::clock()进行了详细说明,大意是在实际使用中他们之间的差值才是有意义的,可以用来计算程序计算的大致时间。要想得到秒需要用他们的差值除以CLOCKS_PER_SEC。CLOCKS_PER_SEC表示的是每秒钟的时钟计数,之所以说是计算程序执行的大致时间是因为操作系统分配的资源不同导致的。倘若程序的多线程的就有可能计算的比实际时间更快。若有其他程序也在使用CPU就可能导致时间会比实际时间更慢。
在windows下timer最大是596.523小时,最小是0.001s,所以要计时的程序太长或对精确度要求很高,不要使用此类。
0 0
- 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-timer库学习
- 浅尝boost之timer
- boost--timer库
- boost库-timer
- Boost----- timer库
- boost timer库使用
- 超实用的JavaScript技巧及最佳实践(下)
- 剑灵,果然快不行了
- linux的Eclipse下安装tomcat
- 采药【(0-1)背包问题】
- VirtualBox虚拟机 Ubuntu分辨率太小的解决方案
- boost::timer
- 2013年大学第一学期心得体会
- 在服务端录制语音视频
- 津津的储蓄计划
- 新的一天
- asfit算法学习
- 超级程序员神话
- 合并果子
- "等差三元组"