]> git.lyx.org Git - lyx.git/blob - boost/boost/timer.hpp
Boost 1.31.0
[lyx.git] / boost / boost / timer.hpp
1 //  boost timer.hpp header file  ---------------------------------------------//
2
3 //  Copyright Beman Dawes 1994-99.
4 //  See accompanying license for terms and conditions of use.
5
6 //  See http://www.boost.org/libs/timer for documentation.
7
8 //  Revision History
9 //  01 Apr 01  Modified to use new <boost/limits.hpp> header. (JMaddock)
10 //  12 Jan 01  Change to inline implementation to allow use without library
11 //             builds. See docs for more rationale. (Beman Dawes) 
12 //  25 Sep 99  elapsed_max() and elapsed_min() added (John Maddock)
13 //  16 Jul 99  Second beta
14 //   6 Jul 99  Initial boost version
15
16 #ifndef BOOST_TIMER_HPP
17 #define BOOST_TIMER_HPP
18
19 #include <boost/config.hpp>
20 #include <ctime>
21 #include <boost/limits.hpp>
22
23 # ifdef BOOST_NO_STDC_NAMESPACE
24     namespace std { using ::clock_t; using ::clock; }
25 # endif
26
27
28 namespace boost {
29
30 //  timer  -------------------------------------------------------------------//
31
32 //  A timer object measures elapsed time.
33
34 //  It is recommended that implementations measure wall clock rather than CPU
35 //  time since the intended use is performance measurement on systems where
36 //  total elapsed time is more important than just process or CPU time.
37
38 //  Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
39 //  due to implementation limitations.  The accuracy of timings depends on the
40 //  accuracy of timing information provided by the underlying platform, and
41 //  this varies a great deal from platform to platform.
42
43 class timer
44 {
45  public:
46          timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
47 //         timer( const timer& src );      // post: elapsed()==src.elapsed()
48 //        ~timer(){}
49 //  timer& operator=( const timer& src );  // post: elapsed()==src.elapsed()
50   void   restart() { _start_time = std::clock(); } // post: elapsed()==0
51   double elapsed() const                  // return elapsed time in seconds
52     { return  double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
53
54   double elapsed_max() const   // return estimated maximum value for elapsed()
55   // Portability warning: elapsed_max() may return too high a value on systems
56   // where std::clock_t overflows or resets at surprising values.
57   {
58     return (double(std::numeric_limits<std::clock_t>::max())
59        - double(_start_time)) / double(CLOCKS_PER_SEC); 
60   }
61
62   double elapsed_min() const            // return minimum value for elapsed()
63    { return double(1)/double(CLOCKS_PER_SEC); }
64
65  private:
66   std::clock_t _start_time;
67 }; // timer
68
69 } // namespace boost
70
71 #endif  // BOOST_TIMER_HPP