nuclear@0: // boost timer.hpp header file ---------------------------------------------// nuclear@0: nuclear@0: // Copyright Beman Dawes 1994-99. Distributed under the Boost nuclear@0: // Software License, Version 1.0. (See accompanying file nuclear@0: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) nuclear@0: nuclear@0: // See http://www.boost.org/libs/timer for documentation. nuclear@0: nuclear@0: // Revision History nuclear@0: // 01 Apr 01 Modified to use new header. (JMaddock) nuclear@0: // 12 Jan 01 Change to inline implementation to allow use without library nuclear@0: // builds. See docs for more rationale. (Beman Dawes) nuclear@0: // 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock) nuclear@0: // 16 Jul 99 Second beta nuclear@0: // 6 Jul 99 Initial boost version nuclear@0: nuclear@0: #ifndef BOOST_TIMER_HPP nuclear@0: #define BOOST_TIMER_HPP nuclear@0: nuclear@0: //#include nuclear@0: #include nuclear@0: //#include nuclear@0: nuclear@0: # ifdef BOOST_NO_STDC_NAMESPACE nuclear@0: namespace std { using ::clock_t; using ::clock; } nuclear@0: # endif nuclear@0: nuclear@0: nuclear@0: namespace boost { nuclear@0: nuclear@0: // timer -------------------------------------------------------------------// nuclear@0: nuclear@0: // A timer object measures elapsed time. nuclear@0: nuclear@0: // It is recommended that implementations measure wall clock rather than CPU nuclear@0: // time since the intended use is performance measurement on systems where nuclear@0: // total elapsed time is more important than just process or CPU time. nuclear@0: nuclear@0: // Warnings: The maximum measurable elapsed time may well be only 596.5+ hours nuclear@0: // due to implementation limitations. The accuracy of timings depends on the nuclear@0: // accuracy of timing information provided by the underlying platform, and nuclear@0: // this varies a great deal from platform to platform. nuclear@0: nuclear@0: class timer nuclear@0: { nuclear@0: public: nuclear@0: timer() { _start_time = std::clock(); } // postcondition: elapsed()==0 nuclear@0: // timer( const timer& src ); // post: elapsed()==src.elapsed() nuclear@0: // ~timer(){} nuclear@0: // timer& operator=( const timer& src ); // post: elapsed()==src.elapsed() nuclear@0: void restart() { _start_time = std::clock(); } // post: elapsed()==0 nuclear@0: double elapsed() const // return elapsed time in seconds nuclear@0: { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; } nuclear@0: nuclear@0: double elapsed_max() const // return estimated maximum value for elapsed() nuclear@0: // Portability warning: elapsed_max() may return too high a value on systems nuclear@0: // where std::clock_t overflows or resets at surprising values. nuclear@0: { nuclear@0: return (double((std::numeric_limits::max)()) nuclear@0: - double(_start_time)) / double(CLOCKS_PER_SEC); nuclear@0: } nuclear@0: nuclear@0: double elapsed_min() const // return minimum value for elapsed() nuclear@0: { return double(1)/double(CLOCKS_PER_SEC); } nuclear@0: nuclear@0: private: nuclear@0: std::clock_t _start_time; nuclear@0: }; // timer nuclear@0: nuclear@0: } // namespace boost nuclear@0: nuclear@0: #endif // BOOST_TIMER_HPP