summaryrefslogtreecommitdiff
path: root/boost/timer
diff options
context:
space:
mode:
authorAnas Nashif <anas.nashif@intel.com>2012-10-30 12:57:26 -0700
committerAnas Nashif <anas.nashif@intel.com>2012-10-30 12:57:26 -0700
commit1a78a62555be32868418fe52f8e330c9d0f95d5a (patch)
treed3765a80e7d3b9640ec2e930743630cd6b9fce2b /boost/timer
downloadboost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.gz
boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.tar.bz2
boost-1a78a62555be32868418fe52f8e330c9d0f95d5a.zip
Imported Upstream version 1.49.0upstream/1.49.0
Diffstat (limited to 'boost/timer')
-rw-r--r--boost/timer/config.hpp53
-rw-r--r--boost/timer/timer.hpp138
2 files changed, 191 insertions, 0 deletions
diff --git a/boost/timer/config.hpp b/boost/timer/config.hpp
new file mode 100644
index 0000000000..adf223d3e4
--- /dev/null
+++ b/boost/timer/config.hpp
@@ -0,0 +1,53 @@
+// boost/timer/config.hpp -----------------------------------------------------------//
+
+// Copyright Beman Dawes 2003, 2006, 2011
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/timer for documentation.
+
+#ifndef BOOST_TIMER_CONFIG_HPP
+#define BOOST_TIMER_CONFIG_HPP
+
+#include <boost/config.hpp>
+
+#include <boost/system/api_config.hpp>
+
+// This header implements separate compilation features as described in
+// http://www.boost.org/more/separate_compilation.html
+
+// enable dynamic or static linking as requested --------------------------------------//
+
+#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK)
+# if defined(BOOST_TIMER_SOURCE)
+# define BOOST_TIMER_DECL BOOST_SYMBOL_EXPORT
+# else
+# define BOOST_TIMER_DECL BOOST_SYMBOL_IMPORT
+# endif
+#else
+# define BOOST_TIMER_DECL
+#endif
+
+// enable automatic library variant selection ----------------------------------------//
+
+#if !defined(BOOST_TIMER_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_TIMER_NO_LIB)
+//
+// Set the name of our library, this will get undef'ed by auto_link.hpp
+// once it's done with it:
+//
+#define BOOST_LIB_NAME boost_timer
+//
+// If we're importing code from a dll, then tell auto_link.hpp about it:
+//
+#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_TIMER_DYN_LINK)
+# define BOOST_DYN_LINK
+#endif
+//
+// And include the header that does the work:
+//
+#include <boost/config/auto_link.hpp>
+#endif // auto-linking disabled
+
+#endif // BOOST_TIMER_CONFIG_HPP
+
diff --git a/boost/timer/timer.hpp b/boost/timer/timer.hpp
new file mode 100644
index 0000000000..4e6c271a84
--- /dev/null
+++ b/boost/timer/timer.hpp
@@ -0,0 +1,138 @@
+// boost/timer/timer.hpp -------------------------------------------------------------//
+
+// Copyright Beman Dawes 1994-2007, 2011
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_TIMER_TIMER_HPP
+#define BOOST_TIMER_TIMER_HPP
+
+#include <boost/config/warning_disable.hpp>
+
+#include <boost/timer/config.hpp>
+#include <boost/chrono/chrono.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <cstring>
+#include <ostream>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+# if defined(_MSC_VER)
+# pragma warning(push) // Save warning settings
+# pragma warning(disable : 4251) // disable warning: class 'std::basic_string<_Elem,_Traits,_Ax>'
+# endif // needs to have dll-interface...
+
+//--------------------------------------------------------------------------------------//
+
+// TODO:
+//
+// * Add BOOST_NOEXCEPT where applicable
+
+//--------------------------------------------------------------------------------------//
+
+namespace boost
+{
+namespace timer
+{
+ class cpu_timer;
+ class auto_cpu_timer;
+
+ typedef boost::int_least64_t nanosecond_type;
+
+ struct cpu_times
+ {
+ nanosecond_type wall;
+ nanosecond_type user;
+ nanosecond_type system;
+
+ void clear() { wall = user = system = 0LL; }
+ };
+
+ const short default_places = 6;
+
+ BOOST_TIMER_DECL
+ std::string format(const cpu_times& times, short places, const std::string& format);
+
+ BOOST_TIMER_DECL
+ std::string format(const cpu_times& times, short places = default_places);
+
+// cpu_timer -------------------------------------------------------------------------//
+
+ class BOOST_TIMER_DECL cpu_timer
+ {
+ public:
+
+ // constructor
+ cpu_timer() { start(); }
+
+ // observers
+ bool is_stopped() const { return m_is_stopped; }
+ cpu_times elapsed() const; // does not stop()
+ std::string format(short places, const std::string& format) const
+ { return ::boost::timer::format(elapsed(), places, format); }
+ std::string format(short places = default_places) const
+ { return ::boost::timer::format(elapsed(), places); }
+ // actions
+ void start();
+ void stop();
+ void resume();
+
+ private:
+ cpu_times m_times;
+ bool m_is_stopped;
+ };
+
+// auto_cpu_timer --------------------------------------------------------------------//
+
+ class BOOST_TIMER_DECL auto_cpu_timer : public cpu_timer
+ {
+ public:
+
+ // Explicit defaults for os are not provided to avoid including <iostream>, which has
+ // high costs even when the standard streams are not actually used. Explicit defaults
+ // for format are not provided to avoid order-of-dynamic-initialization issues with a
+ // std::string.
+
+ explicit auto_cpu_timer(short places = default_places); // #1
+ auto_cpu_timer(short places, const std::string& format); // #2
+ explicit auto_cpu_timer(const std::string& format); // #3
+ auto_cpu_timer(std::ostream& os, short places,
+ const std::string& format) // #4
+ : m_places(places), m_os(&os), m_format(format)
+ { start(); }
+ explicit auto_cpu_timer(std::ostream& os, short places = default_places); // #5
+ auto_cpu_timer(std::ostream& os, const std::string& format) // #6
+ : m_places(default_places), m_os(&os), m_format(format)
+ { start(); }
+
+ ~auto_cpu_timer();
+
+ // observers
+ // not particularly useful to users, but allow testing of constructor
+ // postconditions and ease specification of other functionality without resorting
+ // to "for exposition only" private members.
+ std::ostream& ostream() const { return *m_os; }
+ short places() const { return m_places; }
+ const std::string& format_string() const { return m_format; }
+
+ // actions
+ void report();
+
+ private:
+ short m_places;
+ std::ostream* m_os; // stored as ptr so compiler can generate operator=
+ std::string m_format;
+ };
+
+} // namespace timer
+} // namespace boost
+
+# if defined(_MSC_VER)
+# pragma warning(pop) // restore warning settings.
+# endif
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_TIMER_TIMER_HPP