blob: 95ca7b043e74454e091010fc823d5c59373b80ed [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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 <ndnboost/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#include <ndnboost/config.hpp>
21#include <ctime>
22#include <ndnboost/limits.hpp>
23
24# ifdef BOOST_NO_STDC_NAMESPACE
25 namespace std { using ::clock_t; using ::clock; }
26# endif
27
28
29namespace ndnboost {
30
31// timer -------------------------------------------------------------------//
32
33// A timer object measures elapsed time.
34
35// It is recommended that implementations measure wall clock rather than CPU
36// time since the intended use is performance measurement on systems where
37// total elapsed time is more important than just process or CPU time.
38
39// Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
40// due to implementation limitations. The accuracy of timings depends on the
41// accuracy of timing information provided by the underlying platform, and
42// this varies a great deal from platform to platform.
43
44class timer
45{
46 public:
47 timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
48// timer( const timer& src ); // post: elapsed()==src.elapsed()
49// ~timer(){}
50// timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
51 void restart() { _start_time = std::clock(); } // post: elapsed()==0
52 double elapsed() const // return elapsed time in seconds
53 { return double(std::clock() - _start_time) / CLOCKS_PER_SEC; }
54
55 double elapsed_max() const // return estimated maximum value for elapsed()
56 // Portability warning: elapsed_max() may return too high a value on systems
57 // where std::clock_t overflows or resets at surprising values.
58 {
59 return (double((std::numeric_limits<std::clock_t>::max)())
60 - double(_start_time)) / double(CLOCKS_PER_SEC);
61 }
62
63 double elapsed_min() const // return minimum value for elapsed()
64 { return double(1)/double(CLOCKS_PER_SEC); }
65
66 private:
67 std::clock_t _start_time;
68}; // timer
69
70} // namespace ndnboost
71
72#endif // BOOST_TIMER_HPP