1 // boost timer.hpp header file ---------------------------------------------//
\r
3 // Copyright Beman Dawes 1994-99. Distributed under the Boost
\r
4 // Software License, Version 1.0. (See accompanying file
\r
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
\r
7 // See http://www.boost.org/libs/timer for documentation.
\r
10 // 01 Apr 01 Modified to use new <boost/limits.hpp> header. (JMaddock)
\r
11 // 12 Jan 01 Change to inline implementation to allow use without library
\r
12 // builds. See docs for more rationale. (Beman Dawes)
\r
13 // 25 Sep 99 elapsed_max() and elapsed_min() added (John Maddock)
\r
14 // 16 Jul 99 Second beta
\r
15 // 6 Jul 99 Initial boost version
\r
17 #ifndef BOOST_TIMER_HPP
\r
18 #define BOOST_TIMER_HPP
\r
20 #include <boost/config.hpp>
\r
22 #include <boost/limits.hpp>
\r
24 # ifdef BOOST_NO_STDC_NAMESPACE
\r
25 namespace std { using ::clock_t; using ::clock; }
\r
31 // timer -------------------------------------------------------------------//
\r
33 // A timer object measures elapsed time.
\r
35 // It is recommended that implementations measure wall clock rather than CPU
\r
36 // time since the intended use is performance measurement on systems where
\r
37 // total elapsed time is more important than just process or CPU time.
\r
39 // Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
\r
40 // due to implementation limitations. The accuracy of timings depends on the
\r
41 // accuracy of timing information provided by the underlying platform, and
\r
42 // this varies a great deal from platform to platform.
\r
47 timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
\r
48 // timer( const timer& src ); // post: elapsed()==src.elapsed()
\r
50 // timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
\r
51 void restart() { _start_time = std::clock(); } // post: elapsed()==0
\r
52 double elapsed() const // return elapsed time in seconds
\r
53 { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
\r
55 double elapsed_max() const // return estimated maximum value for elapsed()
\r
56 // Portability warning: elapsed_max() may return too high a value on systems
\r
57 // where std::clock_t overflows or resets at surprising values.
\r
59 return (double((std::numeric_limits<std::clock_t>::max)())
\r
60 - double(_start_time)) / double(CLOCKS_PER_SEC);
\r
63 double elapsed_min() const // return minimum value for elapsed()
\r
64 { return double(1)/double(CLOCKS_PER_SEC); }
\r
67 std::clock_t _start_time;
\r
70 } // namespace boost
\r
72 #endif // BOOST_TIMER_HPP
\r