File indexing completed on 2025-01-18 09:52:54
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_TIMER_TIMER_HPP
0009 #define BOOST_TIMER_TIMER_HPP
0010
0011 #include <boost/timer/config.hpp>
0012 #include <boost/cstdint.hpp>
0013 #include <string>
0014 #include <cstring>
0015 #include <ostream>
0016
0017 #include <boost/config/abi_prefix.hpp> // must be the last #include
0018
0019 # if defined(_MSC_VER)
0020 # pragma warning(push)
0021 # pragma warning(disable : 4251)
0022 # endif
0023
0024
0025
0026 namespace boost
0027 {
0028 namespace timer
0029 {
0030 class cpu_timer;
0031 class auto_cpu_timer;
0032
0033 typedef boost::int_least64_t nanosecond_type;
0034
0035 struct cpu_times
0036 {
0037 nanosecond_type wall;
0038 nanosecond_type user;
0039 nanosecond_type system;
0040
0041 void clear() { wall = user = system = 0; }
0042 };
0043
0044 const short default_places = 6;
0045
0046 BOOST_TIMER_DECL
0047 std::string format(const cpu_times& times, short places, const std::string& format);
0048
0049 BOOST_TIMER_DECL
0050 std::string format(const cpu_times& times, short places = default_places);
0051
0052
0053
0054 class BOOST_TIMER_DECL cpu_timer
0055 {
0056 public:
0057
0058
0059 cpu_timer() BOOST_NOEXCEPT { start(); }
0060
0061
0062 bool is_stopped() const BOOST_NOEXCEPT { return m_is_stopped; }
0063 cpu_times elapsed() const BOOST_NOEXCEPT;
0064 std::string format(short places, const std::string& format) const
0065 { return ::boost::timer::format(elapsed(), places, format); }
0066 std::string format(short places = default_places) const
0067 { return ::boost::timer::format(elapsed(), places); }
0068
0069 void start() BOOST_NOEXCEPT;
0070 void stop() BOOST_NOEXCEPT;
0071 void resume() BOOST_NOEXCEPT;
0072
0073 private:
0074 cpu_times m_times;
0075 bool m_is_stopped;
0076 };
0077
0078
0079
0080 class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
0081 {
0082 public:
0083
0084
0085
0086
0087
0088
0089 explicit auto_cpu_timer(short places = default_places);
0090 auto_cpu_timer(short places, const std::string& format);
0091 explicit auto_cpu_timer(const std::string& format);
0092 auto_cpu_timer(std::ostream& os, short places,
0093 const std::string& format)
0094 : m_places(places), m_os(&os), m_format(format)
0095 { start(); }
0096 explicit auto_cpu_timer(std::ostream& os, short places = default_places);
0097 auto_cpu_timer(std::ostream& os, const std::string& format)
0098 : m_places(default_places), m_os(&os), m_format(format)
0099 { start(); }
0100
0101 ~auto_cpu_timer();
0102
0103
0104
0105
0106
0107 std::ostream& ostream() const { return *m_os; }
0108 short places() const { return m_places; }
0109 const std::string& format_string() const { return m_format; }
0110
0111
0112 void report();
0113
0114 private:
0115 short m_places;
0116 std::ostream* m_os;
0117 std::string m_format;
0118 };
0119
0120 }
0121 }
0122
0123 # if defined(_MSC_VER)
0124 # pragma warning(pop)
0125 # endif
0126
0127 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
0128
0129 #endif