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