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

source code of boost/libs/timer/include/boost/timer.hpp