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