1 // boost/timer/timer.hpp -------------------------------------------------------------//
3 // Copyright Beman Dawes 1994-2007, 2011
5 // Distributed under the Boost Software License, Version 1.0.
6 // See http://www.boost.org/LICENSE_1_0.txt
8 #ifndef BOOST_TIMER_TIMER_HPP
9 #define BOOST_TIMER_TIMER_HPP
11 #include <boost/config/warning_disable.hpp>
13 #include <boost/timer/config.hpp>
14 //#include <boost/chrono/chrono.hpp>
15 #include <boost/cstdint.hpp>
20 #include <boost/config/abi_prefix.hpp> // must be the last #include
22 # if defined(_MSC_VER)
23 # pragma warning(push) // Save warning settings
24 # pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
25 # endif // needs to have dll-interface...
27 //--------------------------------------------------------------------------------------//
36 typedef boost::int_least64_t nanosecond_type;
42 nanosecond_type system;
44 void clear() { wall = user = system = 0; }
47 const short default_places = 6;
50 std::string format(const cpu_times& times, short places, const std::string& format);
53 std::string format(const cpu_times& times, short places = default_places);
55 // cpu_timer -------------------------------------------------------------------------//
57 class BOOST_TIMER_DECL cpu_timer
62 cpu_timer() BOOST_NOEXCEPT { start(); }
65 bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; }
66 cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop()
67 std::string format(short places, const std::string& format) const
68 { return ::boost::timer::format(elapsed(), places, format); }
69 std::string format(short places = default_places) const
70 { return ::boost::timer::format(elapsed(), places); }
72 void start() BOOST_NOEXCEPT;
73 void stop() BOOST_NOEXCEPT;
74 void resume() BOOST_NOEXCEPT;
81 // auto_cpu_timer --------------------------------------------------------------------//
83 class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
87 // Explicit defaults for os are not provided to avoid including <iostream>, which has
88 // high costs even when the standard streams are not actually used. Explicit defaults
89 // for format are not provided to avoid order-of-dynamic-initialization issues with a
92 explicit auto_cpu_timer(short places = default_places); // #1
93 auto_cpu_timer(short places, const std::string& format); // #2
94 explicit auto_cpu_timer(const std::string& format); // #3
95 auto_cpu_timer(std::ostream& os, short places,
96 const std::string& format) // #4
97 : m_places(places), m_os(&os), m_format(format)
99 explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
100 auto_cpu_timer(std::ostream& os, const std::string& format) // #6
101 : m_places(default_places), m_os(&os), m_format(format)
107 // not particularly useful to users, but allow testing of constructor
108 // postconditions and ease specification of other functionality without resorting
109 // to "for exposition only" private members.
110 std::ostream& ostream() const { return *m_os; }
111 short places() const { return m_places; }
112 const std::string& format_string() const { return m_format; }
119 std::ostream* m_os; // stored as ptr so compiler can generate operator=
120 std::string m_format;
126 # if defined(_MSC_VER)
127 # pragma warning(pop) // restore warning settings.
130 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
132 #endif // BOOST_TIMER_TIMER_HPP