Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/timer/timer.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // boost/timer/timer.hpp -------------------------------------------------------------// | |
2 | |
3 // Copyright Beman Dawes 1994-2007, 2011 | |
4 | |
5 // Distributed under the Boost Software License, Version 1.0. | |
6 // See http://www.boost.org/LICENSE_1_0.txt | |
7 | |
8 #ifndef BOOST_TIMER_TIMER_HPP | |
9 #define BOOST_TIMER_TIMER_HPP | |
10 | |
11 #include <boost/config/warning_disable.hpp> | |
12 | |
13 #include <boost/timer/config.hpp> | |
14 #include <boost/chrono/chrono.hpp> | |
15 #include <boost/cstdint.hpp> | |
16 #include <string> | |
17 #include <cstring> | |
18 #include <ostream> | |
19 | |
20 #include <boost/config/abi_prefix.hpp> // must be the last #include | |
21 | |
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... | |
26 | |
27 //--------------------------------------------------------------------------------------// | |
28 | |
29 // TODO: | |
30 // | |
31 // * Add BOOST_NOEXCEPT where applicable | |
32 | |
33 //--------------------------------------------------------------------------------------// | |
34 | |
35 namespace boost | |
36 { | |
37 namespace timer | |
38 { | |
39 class cpu_timer; | |
40 class auto_cpu_timer; | |
41 | |
42 typedef boost::int_least64_t nanosecond_type; | |
43 | |
44 struct cpu_times | |
45 { | |
46 nanosecond_type wall; | |
47 nanosecond_type user; | |
48 nanosecond_type system; | |
49 | |
50 void clear() { wall = user = system = 0LL; } | |
51 }; | |
52 | |
53 const short default_places = 6; | |
54 | |
55 BOOST_TIMER_DECL | |
56 std::string format(const cpu_times& times, short places, const std::string& format); | |
57 | |
58 BOOST_TIMER_DECL | |
59 std::string format(const cpu_times& times, short places = default_places); | |
60 | |
61 // cpu_timer -------------------------------------------------------------------------// | |
62 | |
63 class BOOST_TIMER_DECL cpu_timer | |
64 { | |
65 public: | |
66 | |
67 // constructor | |
68 cpu_timer() { start(); } | |
69 | |
70 // observers | |
71 bool is_stopped() const { return m_is_stopped; } | |
72 cpu_times elapsed() const; // does not stop() | |
73 std::string format(short places, const std::string& format) const | |
74 { return ::boost::timer::format(elapsed(), places, format); } | |
75 std::string format(short places = default_places) const | |
76 { return ::boost::timer::format(elapsed(), places); } | |
77 // actions | |
78 void start(); | |
79 void stop(); | |
80 void resume(); | |
81 | |
82 private: | |
83 cpu_times m_times; | |
84 bool m_is_stopped; | |
85 }; | |
86 | |
87 // auto_cpu_timer --------------------------------------------------------------------// | |
88 | |
89 class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer | |
90 { | |
91 public: | |
92 | |
93 // Explicit defaults for os are not provided to avoid including <iostream>, which has | |
94 // high costs even when the standard streams are not actually used. Explicit defaults | |
95 // for format are not provided to avoid order-of-dynamic-initialization issues with a | |
96 // std::string. | |
97 | |
98 explicit auto_cpu_timer(short places = default_places); // #1 | |
99 auto_cpu_timer(short places, const std::string& format); // #2 | |
100 explicit auto_cpu_timer(const std::string& format); // #3 | |
101 auto_cpu_timer(std::ostream& os, short places, | |
102 const std::string& format) // #4 | |
103 : m_places(places), m_os(&os), m_format(format) | |
104 { start(); } | |
105 explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5 | |
106 auto_cpu_timer(std::ostream& os, const std::string& format) // #6 | |
107 : m_places(default_places), m_os(&os), m_format(format) | |
108 { start(); } | |
109 | |
110 ~auto_cpu_timer(); | |
111 | |
112 // observers | |
113 // not particularly useful to users, but allow testing of constructor | |
114 // postconditions and ease specification of other functionality without resorting | |
115 // to "for exposition only" private members. | |
116 std::ostream& ostream() const { return *m_os; } | |
117 short places() const { return m_places; } | |
118 const std::string& format_string() const { return m_format; } | |
119 | |
120 // actions | |
121 void report(); | |
122 | |
123 private: | |
124 short m_places; | |
125 std::ostream* m_os; // stored as ptr so compiler can generate operator= | |
126 std::string m_format; | |
127 }; | |
128 | |
129 } // namespace timer | |
130 } // namespace boost | |
131 | |
132 # if defined(_MSC_VER) | |
133 # pragma warning(pop) // restore warning settings. | |
134 # endif | |
135 | |
136 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas | |
137 | |
138 #endif // BOOST_TIMER_TIMER_HPP |