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/timer/config.hpp>
12 #include <boost/cstdint.hpp>
17 #include <boost/config/abi_prefix.hpp> // must be the last #include
19 # if defined(_MSC_VER)
20 # pragma warning(push) // Save warning settings
21 # pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
22 # endif // needs to have dll-interface...
24 //--------------------------------------------------------------------------------------//
33 typedef boost::int_least64_t nanosecond_type;
39 nanosecond_type system;
41 void clear() { wall = user = system = 0; }
44 const short default_places = 6;
47 std::string format(const cpu_times& times, short places, const std::string& format);
50 std::string format(const cpu_times& times, short places = default_places);
52 // cpu_timer -------------------------------------------------------------------------//
54 class BOOST_TIMER_DECL cpu_timer
59 cpu_timer() BOOST_NOEXCEPT { start(); }
62 bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; }
63 cpu_times elapsed() const BOOST_NOEXCEPT; // does not stop()
64 std::string format(short places, const std::string& format) const
65 { return ::boost::timer::format(elapsed(), places, format); }
66 std::string format(short places = default_places) const
67 { return ::boost::timer::format(elapsed(), places); }
69 void start() BOOST_NOEXCEPT;
70 void stop() BOOST_NOEXCEPT;
71 void resume() BOOST_NOEXCEPT;
78 // auto_cpu_timer --------------------------------------------------------------------//
80 class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
84 // Explicit defaults for os are not provided to avoid including <iostream>, which has
85 // high costs even when the standard streams are not actually used. Explicit defaults
86 // for format are not provided to avoid order-of-dynamic-initialization issues with a
89 explicit auto_cpu_timer(short places = default_places); // #1
90 auto_cpu_timer(short places, const std::string& format); // #2
91 explicit auto_cpu_timer(const std::string& format); // #3
92 auto_cpu_timer(std::ostream& os, short places,
93 const std::string& format) // #4
94 : m_places(places), m_os(&os), m_format(format)
96 explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
97 auto_cpu_timer(std::ostream& os, const std::string& format) // #6
98 : m_places(default_places), m_os(&os), m_format(format)
104 // not particularly useful to users, but allow testing of constructor
105 // postconditions and ease specification of other functionality without resorting
106 // to "for exposition only" private members.
107 std::ostream& ostream() const { return *m_os; }
108 short places() const { return m_places; }
109 const std::string& format_string() const { return m_format; }
116 std::ostream* m_os; // stored as ptr so compiler can generate operator=
117 std::string m_format;
123 # if defined(_MSC_VER)
124 # pragma warning(pop) // restore warning settings.
127 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
129 #endif // BOOST_TIMER_TIMER_HPP