Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65202 - in sandbox/chrono/boost/stopwatches: . detail
From: vicente.botet_at_[hidden]
Date: 2010-09-02 17:04:20


Author: viboes
Date: 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
New Revision: 65202
URL: http://svn.boost.org/trac/boost/changeset/65202

Log:
Added stopwatches files

Added:
   sandbox/chrono/boost/stopwatches/config.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/detail/
   sandbox/chrono/boost/stopwatches/detail/adaptive_string.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/detail/default_out.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/detail/static_assert.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/scoped_stopclock.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/scoped_suspend2.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopclock.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_accumulator.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatch_scoped.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/stopwatches.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/t24_hours.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp (contents, props changed)
   sandbox/chrono/boost/stopwatches/time_formatter.hpp (contents, props changed)

Added: sandbox/chrono/boost/stopwatches/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/config.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,18 @@
+// boost/chrono/config.hpp -------------------------------------------------//
+
+// Copyright Beman Dawes 2003, 2006, 2008
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+#ifndef BOOST_STOPWATCHES_CONFIG_HPP
+#define BOOST_STOPWATCHES_CONFIG_HPP
+
+#include <boost/config.hpp>
+
+
+#endif // BOOST_STOPWATCHES_CONFIG_HPP
+

Added: sandbox/chrono/boost/stopwatches/detail/adaptive_string.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/detail/adaptive_string.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,66 @@
+// boost/chrono/stopwatch_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_DETAIL_ADAPTIVE_STRING_HPP
+#define BOOST_STOPWATCHES_DETAIL_ADAPTIVE_STRING_HPP
+
+#include <string>
+
+namespace boost { namespace stopwatches {
+
+namespace detail {
+
+ /**
+ * this class is a shim between std::string type and wchar_t type.
+ * it accepts a std::string type and returns a std::string or
+ * std::wstring according to the context(e.g. type on the left side
+ * of '=' operator):
+ * - in case of a string type, it forwards the passed-in std::string
+ * - in case of a wstring type, it widens it passed-in std::string
+ * before forwarding
+ *
+ * typical usage:
+ * std::string s = adaptive_string("hello"); // s = "hello"
+ * std::wstring ws = adaptive_string("hello"); // ws = L"hello"
+ * N.B. it doe not do any code conversion like: MBCS <--> UNICODE
+ */
+
+ struct adaptive_string
+ {
+ adaptive_string(const std::string& s):str_(s)
+ {}
+
+ // implicit convert to any basic_string
+ template <
+ typename CharT,
+ typename Traits,
+ class Alloc
+ >
+ operator std::basic_string<CharT, Traits, Alloc>() const
+ {
+ //return str_;
+ std::basic_string<CharT, Traits, Alloc> s;
+ s.assign(str_.begin(), str_.end());
+ return s;
+ }
+ adaptive_string(const adaptive_string& rhs) : str_(rhs.str_)
+ {}
+
+ private:
+ const std::string& str_;
+ adaptive_string& operator=(const adaptive_string&); // = delete;
+ };
+
+
+} // namespace detail
+} // namespace stopwatches
+} // namespace boost
+
+
+#endif

Added: sandbox/chrono/boost/stopwatches/detail/default_out.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/detail/default_out.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,42 @@
+// boost/chrono/stopwatch_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_DETAIL_DEFAULT_OUT_HPP
+#define BOOST_STOPWATCHES_DETAIL_DEFAULT_OUT_HPP
+
+#include <boost/stopwatches/config.hpp>
+#include <iostream>
+
+namespace boost { namespace stopwatches {
+
+
+namespace detail {
+ template <typename CharT,typename Traits>
+ struct default_out;
+ template <typename Traits>
+ struct default_out<char,Traits> {
+ static std::basic_ostream<char,Traits>& apply() {
+ return std::cout;
+ }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <typename Traits>
+ struct default_out<wchar_t,Traits> {
+ static std::basic_ostream<wchar_t,Traits>& apply() {
+ return std::wcout;
+ }
+ };
+#endif
+}
+
+ } // namespace chrono
+} // namespace boost
+
+
+#endif

Added: sandbox/chrono/boost/stopwatches/detail/static_assert.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/detail/static_assert.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,30 @@
+// static_assert.hpp --------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_STOPWATCHES_DETAIL_STATIC_ASSERT_HPP
+#define BOOST_STOPWATCHES_DETAIL_STATIC_ASSERT_HPP
+
+#include <boost/stopwatches/config.hpp>
+
+#ifndef BOOST_NO_STATIC_ASSERT
+#define BOOST_STOPWATCHES_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
+#elif defined(BOOST_STOPWATCHES_USES_STATIC_ASSERT)
+#include <boost/static_assert.hpp>
+#define BOOST_STOPWATCHES_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
+#elif defined(BOOST_STOPWATCHES_USES_MPL_ASSERT)
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#define BOOST_STOPWATCHES_STATIC_ASSERT(CND, MSG, TYPES) \
+ BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
+#elif defined(BOOST_STOPWATCHES_USES_ARRAY_ASSERT)
+#define BOOST_STOPWATCHES_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_JOIN(boost_chrono_test_,__LINE__)[CND]
+#else
+#define BOOST_STOPWATCHES_STATIC_ASSERT(CND, MSG, TYPES)
+#endif
+
+#endif // BOOST_STOPWATCHES_DETAIL_STATIC_ASSERT_HPP

Added: sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,278 @@
+// boost/stopwatches/lightweight_stopwatch.hpp ------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_LIGHTWEIGHT_STOPWATCH__HPP
+#define BOOST_STOPWATCHES_LIGHTWEIGHT_STOPWATCH__HPP
+
+#include <utility>
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/stopwatch_scoped.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/accumulators/framework/accumulator_set.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace stopwatches
+ {
+
+ template <typename Features, typename Weight=void>
+ struct lightweight_stopwatch_accumulator_set_traits {
+ template <typename D>
+ struct apply {
+ struct type {
+ typedef accumulators::accumulator_set<typename D::rep, Features, Weight> storage_type;
+ typedef D duration_type;
+ static duration_type get_duration(storage_type& acc_) { return duration_type(accumulators::sum(acc_)); }
+ static void set_duration(storage_type& acc_, duration_type d) { acc_(d.count()); }
+ static void reset(storage_type& acc_) { acc_=storage_type(); }
+ };
+ };
+ };
+
+ struct lightweight_stopwatch_identity_traits {
+ template <typename D>
+ struct apply {
+ struct type {
+ typedef D duration_type;
+ typedef duration_type storage_type;
+ static duration_type get_duration(storage_type& acc_) { return acc_; }
+ static void set_duration(storage_type& acc_, duration_type d) { acc_=d; }
+ static void reset(storage_type& acc_) { acc_=storage_type(); }
+ };
+ };
+
+ };
+
+
+ struct dont_start_t{};
+ static const dont_start_t dont_start = {};
+
+ // forward declaration
+ template <
+ typename Clock=chrono::high_resolution_clock,
+ typename Traits=lightweight_stopwatch_identity_traits
+ >
+ class lightweight_stopwatch;
+
+
+//--------------------------------------------------------------------------------------//
+ template <typename Clock, typename Traits>
+ class lightweight_stopwatch
+ {
+ public:
+ typedef typename Traits::template apply<typename Clock::duration>::type traits;
+ typedef typename traits::storage_type storage_type;
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
+ typedef typename Clock::rep rep;
+ typedef typename Clock::period period;
+
+ explicit lightweight_stopwatch( storage_type& acc, system::error_code & ec = system::throws )
+ : running_(false), suspended_(false),
+ start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
+ , storage_(&acc), construction_(clock::now( ))
+ {
+ start(ec);
+ }
+
+ lightweight_stopwatch( storage_type& acc, const dont_start_t& )
+ : running_(false), suspended_(false),
+ start_(duration::zero()), level_(0), partial_(duration::zero()), suspend_level_(0)
+ , storage_(&acc), construction_(clock::now( ))
+ {
+ }
+
+ ~lightweight_stopwatch() {
+ system::error_code ec;
+ stop(ec);
+ }
+
+
+//--------------------------------------------------------------------------------------//
+ std::pair<duration, time_point> restart( system::error_code & ec = system::throws )
+ {
+ time_point tmp=clock::now( ec );
+ if (ec) return time_point();
+ if (running_&&(level_==1)) {
+ partial_ += tmp - start_;
+ traits::set_duration(get_storage(),partial_);
+ partial_=duration::zero();
+ } else {
+ running_=true;
+ }
+ start_=tmp;
+ return std::make_pair(traits::get_duration(get_storage()),start_);
+ }
+
+ time_point start( system::error_code & ec = system::throws )
+ {
+ if (!running_) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ ++level_;
+ running_ = true;
+ return start_;
+ } else {
+ ++level_;
+ ec.clear();
+ return time_point();
+ }
+ }
+
+ duration stop( system::error_code & ec = system::throws )
+ {
+ if (running_ && (--level_==0)) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration::zero();
+ partial_ += tmp - start_;
+ traits::set_duration(get_storage(),partial_);
+ partial_=duration::zero();
+ running_=false;
+ return traits::get_duration(get_storage());
+ } else {
+ ec.clear();
+ return duration::zero();
+ }
+ }
+
+ duration suspend( system::error_code & ec = system::throws )
+ {
+ if (running_) {
+ if (!suspended_) {
+ time_point tmp=clock::now( ec );
+ if (ec) return duration::zero();
+ ++suspend_level_;
+ partial_ += tmp - start_;
+ suspended_=true;
+ return traits::get_duration(get_storage());
+ } else {
+ ++suspend_level_;
+ ec.clear();
+ return duration::zero();
+ }
+ } else {
+ ec.clear();
+ return duration::zero();
+ }
+ }
+
+ time_point resume( system::error_code & ec = system::throws )
+ {
+ if (suspended_&&(--suspend_level_==0)) {
+ time_point tmp = clock::now( ec );
+ if (ec) return time_point();
+ start_ = tmp;
+ suspended_=false;
+ return start_;
+ } else {
+ ec.clear();
+ return time_point();
+ }
+ }
+
+ duration elapsed( system::error_code & ec = system::throws )
+ {
+ if (running_) {
+ if (suspended_)
+ return traits::get_duration(get_storage());
+ else {
+ time_point tmp = clock::now( ec );
+ if (ec) return duration::zero();
+ return traits::get_duration(get_storage())+tmp - start_;
+ }
+ } else {
+ return traits::get_duration(get_storage());
+ }
+ }
+
+ time_point now( system::error_code & ec = system::throws )
+ {
+ return time_point(elapsed( ec ));
+ }
+
+ void reset( system::error_code & ec = system::throws )
+ {
+ construction_=clock::now( ec );
+ if (ec) return;
+ traits::reset(get_storage());
+ running_=false;
+ suspended_=false;
+ partial_ = duration::zero();
+ start_ = time_point(duration::zero());
+ level_=0;
+ suspend_level_=0;
+ }
+
+ storage_type& get_storage( )
+ {
+ return *storage_;
+ }
+
+ duration lifetime( system::error_code & ec = system::throws )
+ {
+ return clock::now( ec ) - construction_;
+ }
+
+ typedef stopwatch_runner<lightweight_stopwatch<Clock,Traits> > scoped_run;
+ typedef stopwatch_stopper<lightweight_stopwatch<Clock,Traits> > scoped_stop;
+ typedef stopwatch_suspender<lightweight_stopwatch<Clock,Traits> > scoped_suspend;
+ typedef stopwatch_resumer<lightweight_stopwatch<Clock,Traits> > scoped_resume;
+ private:
+ bool running_;
+ bool suspended_;
+ time_point start_;
+ std::size_t level_;
+ duration partial_;
+ std::size_t suspend_level_;
+ storage_type* storage_;
+ time_point construction_;
+ };
+
+//--------------------------------------------------------------------------------------//
+ typedef accumulators::features<
+ accumulators::tag::count,
+ accumulators::tag::sum,
+ accumulators::tag::min,
+ accumulators::tag::max,
+ accumulators::tag::mean
+ > default_features;
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::system_clock > system_lightweight_stopwatch;
+#ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::monotonic_clock > monotonic_lightweight_stopwatch;
+#endif
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::high_resolution_clock > high_resolution_lightweight_stopwatch;
+
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::system_clock,
+ lightweight_stopwatch_accumulator_set_traits<default_features> > system_lightweight_stopwatch_accumulator;
+#ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::monotonic_clock,
+ lightweight_stopwatch_accumulator_set_traits<default_features> > monotonic_lightweight_stopwatch_accumulator;
+#endif
+ typedef boost::stopwatches::lightweight_stopwatch< boost::chrono::high_resolution_clock,
+ lightweight_stopwatch_accumulator_set_traits<default_features> > high_resolution_lightweight_stopwatch_accumulator;
+
+//--------------------------------------------------------------------------------------//
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/scoped_stopclock.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/scoped_stopclock.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,122 @@
+// boost/stopwatches/stopclock.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_SCOPED_STOPCLOCK_HPP
+#define BOOST_STOPWATCHES_SCOPED_STOPCLOCK_HPP
+
+#include <boost/stopwatches/stopwatch_reporter.hpp>
+#include <boost/stopwatches/stopwatch.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/stopwatches/time_formatter.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopclock<> _;
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock=chrono::process_cpu_clock, class Formatter=typename stopwatch_reporter_default_formatter<stopwatches::stopwatch<Clock> >::type >
+ class scoped_stopclock
+ : public stopwatch_reporter<stopwatches::stopwatch<Clock>, Formatter> {
+ typedef stopwatch_reporter<stopwatches::stopwatch<Clock>, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatches::stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit scoped_stopclock( const string_type& func, system::error_code & ec = system::throws )
+ : base_type(ec), func_(func)
+ { begin(); }
+ scoped_stopclock( const string_type& func, ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec), func_(func)
+ { begin(); }
+
+ scoped_stopclock( const string_type& func, ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec), func_(func)
+ { begin(); }
+
+ ~scoped_stopclock() {
+ this->m_os << "}}} " << func_ << " : ";
+ }
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ private:
+ void begin() {
+ this->m_os << "{{{ " << func_ << std::endl;
+ }
+ string_type func_;
+
+ };
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_STOPCLOCK_HPP

Added: sandbox/chrono/boost/stopwatches/scoped_suspend2.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/scoped_suspend2.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,40 @@
+// boost/stopwatches/process_cpu_clocks.hpp -----------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_SCOPED_SUSPEND_CLOCK_HPP
+#define BOOST_STOPWATCHES_SCOPED_SUSPEND_CLOCK_HPP
+
+#include <boost/system/error_code.hpp>
+#include <boost/mpl/bool.hpp>
+
+namespace boost { namespace stopwatches {
+
+
+ template <class Clock>
+ struct is_suspendible : mpl:: false_ {};
+
+ template <class Clock>
+ class scoped_suspend {
+ public:
+ scoped_suspend(system::error_code & ec = system::throws) {
+ ec.clear();
+ }
+ ~scoped_suspend() {}
+ private:
+ //~ scoped_suspend(); // = delete;
+ scoped_suspend(const scoped_suspend&); // = delete;
+ scoped_suspend& operator=(const scoped_suspend&); // = delete;
+ };
+
+
+} // namespace stopwatches
+} // namespace boost
+
+
+#endif // BOOST_STOPWATCHES_PROCESS_CPU_CLOCKS_HPP

Added: sandbox/chrono/boost/stopwatches/stopclock.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopclock.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,292 @@
+// boost/stopwatches/stopclock.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPCLOCK_HPP
+#define BOOST_STOPWATCHES_STOPCLOCK_HPP
+
+#include <boost/chrono/config.hpp>
+#include <boost/stopwatches/detail/static_assert.hpp>
+#include <boost/stopwatches/stopwatch_reporter.hpp>
+#include <boost/stopwatches/stopwatch_formatter.hpp>
+#include <boost/stopwatches/time_formatter.hpp>
+#include <boost/stopwatches/stopwatch.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopclock<> _;
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock>
+ struct stopwatch_reporter_default_formatter<stopwatch<Clock> > {
+ typedef stopwatch_formatter type;
+ };
+
+ template <class Clock>
+ struct wstopwatch_reporter_default_formatter<stopwatch<Clock> > {
+ typedef wstopwatch_formatter type;
+ };
+
+ template <>
+ struct stopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> > {
+ typedef time_formatter type;
+ };
+
+ template <>
+ struct wstopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> > {
+ typedef wtime_formatter type;
+ };
+
+ template <>
+ struct stopwatch_reporter_default_formatter<stopwatch<chrono::suspendible_clock<chrono::process_cpu_clock> > > {
+ typedef stopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> >::type type;
+ };
+
+ template <>
+ struct wstopwatch_reporter_default_formatter<stopwatch<chrono::suspendible_clock<chrono::process_cpu_clock> > > {
+ typedef wstopwatch_reporter_default_formatter<stopwatch<chrono::process_cpu_clock> >::type type;
+ };
+
+
+ template <class Clock, class Formatter>
+ class basic_stopclock : public basic_stopwatch_reporter<stopwatches::stopwatch<Clock>, Formatter> {
+ typedef basic_stopwatch_reporter<stopwatches::stopwatch<Clock>, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatches::stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit basic_stopclock( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit basic_stopclock( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit basic_stopclock( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit basic_stopclock( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ basic_stopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ basic_stopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ basic_stopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ basic_stopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ basic_stopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ basic_stopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+ typedef stopwatch_runner<basic_stopclock> scoped_run;
+ typedef stopwatch_stopper<basic_stopclock> scoped_stop;
+ typedef stopwatch_suspender<basic_stopclock> scoped_suspend;
+ typedef stopwatch_resumer<basic_stopclock> scoped_resume;
+
+ };
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<basic_stopclock<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock=chrono::process_cpu_clock, class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock> >::type>
+ class stopclock;
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<stopclock<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock, class Formatter>
+ class stopclock : public basic_stopclock<Clock, Formatter> {
+ typedef basic_stopclock<Clock, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatches::stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit stopclock( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit stopclock( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit stopclock( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit stopclock( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ stopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ stopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ stopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ stopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ stopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ stopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+ typedef stopwatch_runner<stopclock> scoped_run;
+ typedef stopwatch_stopper<stopclock> scoped_stop;
+ typedef stopwatch_suspender<stopclock> scoped_suspend;
+ typedef stopwatch_resumer<stopclock> scoped_resume;
+
+ };
+
+ typedef stopclock< boost::chrono::system_clock > system_stopclock;
+ #ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef stopclock< boost::chrono::monotonic_clock > monotonic_stopclock;
+ #endif
+ typedef stopclock< boost::chrono::high_resolution_clock > high_resolution_stopclock;
+ typedef stopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock;
+ typedef stopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock;
+ typedef stopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock;
+ typedef stopclock< boost::chrono::process_cpu_clock > process_cpu_stopclock;
+
+ template <class Clock=chrono::process_cpu_clock, class Formatter=typename wstopwatch_reporter_default_formatter<stopwatch<Clock> >::type>
+ class wstopclock;
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<wstopclock<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock, class Formatter>
+ class wstopclock : public basic_stopclock<Clock, Formatter> {
+ typedef basic_stopclock<Clock, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatches::stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit wstopclock( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit wstopclock( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit wstopclock( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit wstopclock( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ wstopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ wstopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ wstopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ wstopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ wstopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ wstopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+ typedef stopwatch_runner<wstopclock> scoped_run;
+ typedef stopwatch_stopper<wstopclock> scoped_stop;
+ typedef stopwatch_suspender<wstopclock> scoped_suspend;
+ typedef stopwatch_resumer<wstopclock> scoped_resume;
+
+ };
+
+ typedef wstopclock< boost::chrono::system_clock > system_wstopclock;
+ #ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef wstopclock< boost::chrono::monotonic_clock > monotonic_wstopclock;
+ #endif
+ typedef wstopclock< boost::chrono::high_resolution_clock > high_resolution_wstopclock;
+ typedef wstopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock;
+ typedef wstopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock;
+ typedef wstopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock;
+ typedef wstopclock< boost::chrono::process_cpu_clock > process_cpu_wstopclock;
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_STOPCLOCK_HPP

Added: sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopclock_accumulator.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,294 @@
+// boost/stopwatches/stopclock.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_HPP
+#define BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_HPP
+
+#include <boost/stopwatches/config.hpp>
+#include <boost/stopwatches/detail/static_assert.hpp>
+
+#include <boost/stopwatches/stopwatch_reporter.hpp>
+#include <boost/stopwatches/stopwatch_accumulator.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_formatter.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopclock<> _;
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock, typename Features, typename Weight>
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Features,Weight> > {
+ typedef stopwatch_accumulator_formatter type;
+ };
+
+ template <class Clock, typename Features, typename Weight>
+ struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Features,Weight> > {
+ typedef wstopwatch_accumulator_formatter type;
+ };
+
+ template <typename Features, typename Weight>
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock,Features,Weight> > {
+ typedef stopwatch_accumulator_time_formatter type;
+ };
+
+ template <typename Features, typename Weight>
+ struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock, Features,Weight> > {
+ typedef wstopwatch_accumulator_time_formatter type;
+ };
+
+ template <typename Features, typename Weight>
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
+ typedef stopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock> >::type type;
+ };
+
+ template <typename Features, typename Weight>
+ struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::suspendible_clock<chrono::process_cpu_clock>, Features,Weight> > {
+ typedef wstopwatch_reporter_default_formatter<stopwatch_accumulator<chrono::process_cpu_clock> >::type type;
+ };
+
+
+ template <class Clock, class Formatter>
+ class basic_stopclock_accumulator : public basic_stopwatch_reporter<stopwatch_accumulator<Clock>, Formatter> {
+ typedef basic_stopwatch_reporter<stopwatch_accumulator<Clock>, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit basic_stopclock_accumulator( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit basic_stopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit basic_stopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit basic_stopclock_accumulator( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ basic_stopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ basic_stopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ basic_stopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ basic_stopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ basic_stopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ basic_stopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+
+ typedef stopwatch_runner<basic_stopclock_accumulator> scoped_run;
+ typedef stopwatch_stopper<basic_stopclock_accumulator> scoped_stop;
+ typedef stopwatch_suspender<basic_stopclock_accumulator> scoped_suspend;
+ typedef stopwatch_resumer<basic_stopclock_accumulator> scoped_resume;
+ };
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<basic_stopclock_accumulator<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock=chrono::high_resolution_clock, class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock> >::type>
+ class stopclock_accumulator;
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<stopclock_accumulator<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock, class Formatter>
+ class stopclock_accumulator : public basic_stopclock_accumulator<Clock, Formatter> {
+ typedef basic_stopclock_accumulator<Clock, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit stopclock_accumulator( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit stopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit stopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit stopclock_accumulator( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ stopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ stopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ stopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ stopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ stopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ stopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+
+ typedef stopwatch_runner<stopclock_accumulator> scoped_run;
+ typedef stopwatch_stopper<stopclock_accumulator> scoped_stop;
+ typedef stopwatch_suspender<stopclock_accumulator> scoped_suspend;
+ typedef stopwatch_resumer<stopclock_accumulator> scoped_resume;
+ };
+
+ typedef stopclock_accumulator< boost::chrono::system_clock > system_stopclock_accumulator;
+ #ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef stopclock_accumulator< boost::chrono::monotonic_clock > monotonic_stopclock_accumulator;
+ #endif
+ typedef stopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopclock_accumulator;
+ typedef stopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock_accumulator;
+ typedef stopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock_accumulator;
+ typedef stopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock_accumulator;
+ typedef stopclock_accumulator< boost::chrono::process_cpu_clock > process_cpu_stopclock_accumulator;
+
+ template <class Clock=chrono::high_resolution_clock, class Formatter=typename wstopwatch_reporter_default_formatter<stopwatch_accumulator<Clock> >::type>
+ class wstopclock_accumulator;
+
+ template <class Clock, class Formatter>
+ struct stopwatch_reporter_default_formatter<wstopclock_accumulator<Clock,Formatter> > {
+ typedef Formatter type;
+ };
+
+ template <class Clock, class Formatter>
+ class wstopclock_accumulator : public basic_stopclock_accumulator<Clock, Formatter> {
+ typedef basic_stopclock_accumulator<Clock, Formatter> base_type;
+ public:
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit wstopclock_accumulator( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit wstopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit wstopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit wstopclock_accumulator( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ wstopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ wstopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ wstopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ wstopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ wstopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ wstopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+
+ typedef stopwatch_runner<wstopclock_accumulator> scoped_run;
+ typedef stopwatch_stopper<wstopclock_accumulator> scoped_stop;
+ typedef stopwatch_suspender<wstopclock_accumulator> scoped_suspend;
+ typedef stopwatch_resumer<wstopclock_accumulator> scoped_resume;
+ };
+
+ typedef wstopclock_accumulator< boost::chrono::system_clock > system_wstopclock_accumulator;
+ #ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef wstopclock_accumulator< boost::chrono::monotonic_clock > monotonic_wstopclock_accumulator;
+ #endif
+ typedef wstopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_wstopclock_accumulator;
+ typedef wstopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock_accumulator;
+ typedef wstopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock_accumulator;
+ typedef wstopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock_accumulator;
+ typedef wstopclock_accumulator< boost::chrono::process_cpu_clock > process_cpu_wstopclock_accumulator;
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_STOPCLOCK_HPP

Added: sandbox/chrono/boost/stopwatches/stopwatch.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,76 @@
+// boost/stopwatches/stopwatch.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_HPP
+
+#include <utility>
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/stopwatch_scoped.hpp>
+#include <boost/stopwatches/lightweight_stopwatch.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/utility/base_from_member.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace stopwatches
+ {
+
+//--------------------------------------------------------------------------------------//
+// stopwatch
+//
+//~ A stopwatch is a class designed to measure the amount of time elapsed from a particular time
+//~ when activated to when it is deactivated.
+
+//~ Calling start starts the timer running, and calling stop stops it.
+//~ A call to reset resets the stopwatch to zero.
+//~ A stopwatch can also also used to record split times or lap times.
+//~ The elapsed time since the last start is available through the elapsed function.
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock=chrono::high_resolution_clock>
+ class stopwatch;
+
+ //~ struct dont_start_t{};
+ //~ static const dont_start_t dont_start = {};
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock>
+ class stopwatch : private base_from_member<typename Clock::duration>, public lightweight_stopwatch<Clock>
+ {
+ public:
+ typedef base_from_member<typename Clock::duration> pbase_type;
+ explicit stopwatch( system::error_code & ec = system::throws )
+ : pbase_type(), lightweight_stopwatch<Clock>(pbase_type::member, ec)
+ {
+ }
+
+ explicit stopwatch( const dont_start_t& t )
+ : pbase_type(), lightweight_stopwatch<Clock>(pbase_type::member, t)
+ { }
+
+ };
+
+//--------------------------------------------------------------------------------------//
+ typedef boost::stopwatches::stopwatch< boost::chrono::system_clock > system_stopwatch;
+#ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef boost::stopwatches::stopwatch< boost::chrono::monotonic_clock > monotonic_stopwatch;
+#endif
+ typedef boost::stopwatches::stopwatch< boost::chrono::high_resolution_clock > high_resolution_stopwatch;
+
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_accumulator.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,87 @@
+// boost/stopwatches/stopwatch_accumulator.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_HPP
+
+#include <utility>
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/stopwatch_scoped.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/stopwatches/lightweight_stopwatch.hpp>
+#include <boost/utility/base_from_member.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace stopwatches
+ {
+
+//--------------------------------------------------------------------------------------//
+// stopwatch
+//
+//~ A stopwatch accumulator is a class designed to measure the amount of time elapsed from a particular time
+//~ when activated to when it is deactivated.
+
+//~ Calling start starts the timer running, and calling stop stops it.
+//~ A call to reset resets the stopwatch to zero.
+//~ A stopwatch can also be used to record split times or lap times.
+//~ The elapsed time since the last start is available through the elapsed function.
+//--------------------------------------------------------------------------------------//
+
+ // forward declaration
+ template <class Clock=chrono::high_resolution_clock,
+ typename Features=accumulators::features<
+ accumulators::tag::count,
+ accumulators::tag::sum,
+ accumulators::tag::min,
+ accumulators::tag::max,
+ accumulators::tag::mean >,
+ typename Weight=void
+ >
+ class stopwatch_accumulator;
+
+
+//--------------------------------------------------------------------------------------//
+
+ template <class Clock, typename Features, typename Weight>
+ class stopwatch_accumulator
+ : private base_from_member<
+ typename accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight>
+ //~ typename lightweight_stopwatch_accumulator_set_traits<Features,Weight>::template apply<Clock::duration>::storage_type
+ >,
+ public lightweight_stopwatch<Clock,lightweight_stopwatch_accumulator_set_traits<Features,Weight> >
+ {
+ public:
+ typedef base_from_member<typename accumulators::accumulator_set<typename Clock::duration::rep, Features, Weight> > pbase_type;
+
+ stopwatch_accumulator( )
+ : pbase_type(),
+ lightweight_stopwatch<Clock,lightweight_stopwatch_accumulator_set_traits<Features,Weight> >(pbase_type::member, dont_start)
+ { }
+ };
+
+//--------------------------------------------------------------------------------------//
+ typedef boost::stopwatches::stopwatch_accumulator< boost::chrono::system_clock > system_stopwatch_accumulator;
+#ifdef BOOST_STOPWATCHES_HAS_CLOCK_MONOTONIC
+ typedef boost::stopwatches::stopwatch_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_accumulator;
+#endif
+ typedef boost::stopwatches::stopwatch_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopwatch_accumulator;
+
+//--------------------------------------------------------------------------------------//
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,172 @@
+// boost/stopwatches/stopwatch_accumulator_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_FORMATTER_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+#include <boost/stopwatches/detail/default_out.hpp>
+#include <boost/stopwatches/detail/adaptive_string.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/framework/accumulator_set.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+#define BOOST_STOPWATCHES_ACCUMULATOR_FORMAT_DEFAULT "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%\n"
+
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_stopwatch_accumulator_formatter {
+ public:
+ typedef std::basic_string<CharT,Traits,Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+ static ostream_type & default_os();
+ static const char_type* default_format();
+ static string_type format(const char_type* s) {
+ string_type res(s);
+ res += boost::stopwatches::detail::adaptive_string(" : ");
+ res += default_format();
+ return res;
+ }
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ if (&ec==&system::throws) ec.clear();
+
+ typedef typename Stopwatch::storage_type accumulator;
+ typedef typename Stopwatch::duration duration_t;
+ accumulator& acc = stopwatch_.get_storage();
+ duration_t lt= stopwatch_.lifetime(ec);
+ if (ec) return;
+
+ //if ( d < duration_t::zero() ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ boost::io::ios_flags_saver ifs( os );
+ os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+ boost::io::ios_precision_saver ips( os );
+ os.precision( places );
+
+ for ( ; *format; ++format ) {
+ if ( (*format != '%') || (!*(format+1)) || (!std::strchr("acflmMps", *(format+1))) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 's':
+ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count();
+ break;
+ case 'm':
+ os << boost::chrono::duration<double>(duration_t((accumulators::min)(acc))).count();
+ break;
+ case 'M':
+ os << boost::chrono::duration<double>(duration_t((accumulators::max)(acc))).count();
+ break;
+ case 'a':
+ os << ((accumulators::count(acc)>0)
+ //? boost::chrono::duration<double>(duration_t(typename duration_t::rep(accumulators::mean(acc)))).count()
+ ? boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count() / accumulators::count(acc)
+ : 0);
+ break;
+ case 'c':
+ os << accumulators::count(acc);
+ break;
+ case 'f':
+ os << ((accumulators::count(acc)>0)
+ ? accumulators::count(acc)/boost::chrono::duration<double>(lt)
+ : 0);
+ break;
+ case 'l':
+ os << boost::chrono::duration<double>(lt).count();
+ break;
+ case 'p':
+ os << int(boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count()*100/boost::chrono::duration<double>(lt).count());
+ break;
+ default:
+ assert(0 && "basic_stopwatch_accumulator_formatter internal logic error");
+ }
+ }
+ }
+ }
+ };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_stopwatch_accumulator_formatter_default_format;
+ template <>
+ struct basic_stopwatch_accumulator_formatter_default_format<char> {
+ static const char* apply() {return BOOST_STOPWATCHES_ACCUMULATOR_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_stopwatch_accumulator_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%\n"; }
+ };
+
+#endif
+}
+
+ template <typename CharT,typename Traits, class Alloc>
+ const typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::char_type*
+ basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_accumulator_formatter_default_format<CharT>::apply();
+ }
+
+ template <typename CharT,typename Traits, class Alloc>
+ typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::default_os() { return detail::default_out<CharT,Traits>::apply(); }
+
+ typedef basic_stopwatch_accumulator_formatter<char> stopwatch_accumulator_formatter;
+ typedef basic_stopwatch_accumulator_formatter<wchar_t> wstopwatch_accumulator_formatter;
+
+} // namespace stopwatches
+} // namespace boost
+
+#define BOOST_STOPWATCHES_ACCUMULATOR_FORMAT(F) boost::stopwatches::detail::adaptive_string(F " : " BOOST_STOPWATCHES_ACCUMULATOR_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT boost::stopwatches::stopwatch_accumulator_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT BOOST_STOPWATCHES_ACCUMULATOR_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,198 @@
+// boost/stopwatches/stopwatch_accumulator_time_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_TIMES_FORMATTER_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_ACCUMULATOR_TIMES_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+#include <boost/stopwatches/detail/default_out.hpp>
+#include <boost/stopwatches/detail/adaptive_string.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics.hpp>
+#include <boost/accumulators/framework/accumulator_set.hpp>
+#include <boost/accumulators/statistics/sum.hpp>
+#include <boost/accumulators/statistics/min.hpp>
+#include <boost/accumulators/statistics/max.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+#include <boost/stopwatches/time_formatter.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+//~ #define BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT_DEFAULT "%c times, sum=%s, min=%m, max=%M, mean=%a, frequency=%fHz, lifetime=%ls, percentage=%p%|real %rs, cpu %cs (%p%), user %us, system %ss\n"
+#define BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT_DEFAULT "%c times, sum %s, min %m, max %M, mean=%a, frequency=%fHz, lifetime=%ls, percentage=%p%\n"
+
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_stopwatch_accumulator_time_formatter {
+ public:
+ typedef std::basic_string<CharT,Traits,Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+ static ostream_type & default_os();
+ static const char_type* default_format();
+ static string_type format(const char_type* s) {
+ string_type res(s);
+ res += boost::stopwatches::detail::adaptive_string(" : ");
+ res += default_format();
+ return res;
+ }
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ if (&ec==&system::throws) ec.clear();
+
+ typedef typename Stopwatch::storage_type accumulator;
+ typedef typename Stopwatch::duration duration_t;
+ accumulator& acc = stopwatch_.get_storage();
+ duration_t lt= stopwatch_.lifetime();
+
+ //if ( d < duration_t::zero() ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ boost::io::ios_flags_saver ifs( os );
+ os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+ boost::io::ios_precision_saver ips( os );
+ os.precision( places );
+
+ const char_type* format2=BOOST_STOPWATCHES_TIME_FORMAT_DEFAULT;
+ //~ for (format2=format ; *format2; ++format2 ) {
+ //~ if (*format2=='|') {++format2; break;}
+ //~ }
+
+ for ( ; *format; ++format ) {
+ if ( (*format != '%') || (!*(format+1)) || (!std::strchr("acflmMps", *(format+1))) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 's':
+ //~ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count();
+ time_formatter::show_time<chrono::process_cpu_clock>(accumulators::sum(acc), format2, places, os, ec);
+ if (ec) return;
+ //~ os << accumulators::sum(acc);
+ break;
+ case 'm':
+ //~ os << boost::chrono::duration<double>(duration_t((accumulators::min)(acc))).count();
+ time_formatter::show_time<chrono::process_cpu_clock>((accumulators::min)(acc), format2, places, os, ec);
+ if (ec) return;
+ //~ os << (accumulators::min)(acc);
+ break;
+ case 'M':
+ //~ os << boost::chrono::duration<double>(duration_t((accumulators::max)(acc))).count();
+ time_formatter::show_time<chrono::process_cpu_clock>((accumulators::max)(acc), format2, places, os, ec);
+ if (ec) return;
+ //~ os << (accumulators::max)(acc);
+ break;
+ case 'a':
+ if (accumulators::count(acc)>0) {
+ //? os << boost::chrono::duration<double>(duration_t(typename duration_t::rep(accumulators::mean(acc)))).count()
+ //~ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count() / accumulators::count(acc)
+ time_formatter::show_time<chrono::process_cpu_clock>(accumulators::sum(acc) / accumulators::count(acc), format2, places, os, ec);
+ if (ec) return;
+ } else {
+ os << 0;
+ }
+ break;
+ case 'c':
+ os << accumulators::count(acc);
+ break;
+ case 'f':
+ if (accumulators::count(acc)>0)
+ //~ os << accumulators::count(acc)/boost::chrono::duration<double>(lt);
+ os << accumulators::count(acc) << "/" << lt.count();
+ else
+ os << 0;
+ break;
+ case 'l':
+ os << lt.count();
+ break;
+ case 'p':
+ //~ os << int(boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count()*100/boost::chrono::duration<double>(lt).count());
+ os << accumulators::sum(acc)*100 << "/" << lt.count();
+ break;
+ default:
+ assert(0 && "basic_stopwatch_accumulator_time_formatter internal logic error");
+ }
+ }
+ }
+ }
+ };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_stopwatch_accumulator_time_formatter_default_format;
+ template <>
+ struct basic_stopwatch_accumulator_time_formatter_default_format<char> {
+ static const char* apply() {return BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_stopwatch_accumulator_time_formatter_default_format<wchar_t> {
+ //~ static const wchar_t* apply() {return L"%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p%|real %rs, cpu %cs (%p%), user %us, system %ss\n"; }
+ static const wchar_t* apply() {return L"%c times, sum %s, min %m, max %M, mean %a, frequency=%fHz, lifetime=%ls, percentage=%p%\n"; }
+ };
+
+#endif
+}
+
+ template <typename CharT,typename Traits, class Alloc>
+ const typename basic_stopwatch_accumulator_time_formatter<CharT,Traits,Alloc>::char_type*
+ basic_stopwatch_accumulator_time_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_accumulator_time_formatter_default_format<CharT>::apply();
+ }
+
+ template <typename CharT,typename Traits, class Alloc>
+ typename basic_stopwatch_accumulator_time_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_stopwatch_accumulator_time_formatter<CharT,Traits,Alloc>::default_os() { return detail::default_out<CharT,Traits>::apply(); }
+
+ typedef basic_stopwatch_accumulator_time_formatter<char> stopwatch_accumulator_time_formatter;
+ typedef basic_stopwatch_accumulator_time_formatter<wchar_t> wstopwatch_accumulator_time_formatter;
+
+
+
+
+} // namespace stopwatches
+} // namespace boost
+
+#define BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT(F) boost::stopwatches::detail::adaptive_string(F " : " BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_STOPWATCHES_ACCUMULATOR_TIME_FUNCTION_FORMAT boost::stopwatches::stopwatch_accumulator_time_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_STOPWATCHES_ACCUMULATOR_TIME_FUNCTION_FORMAT BOOST_STOPWATCHES_ACCUMULATOR_TIME_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,136 @@
+// boost/stopwatches/stopwatch_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_FORMATTER_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/current_function.hpp>
+#include <boost/stopwatches/detail/default_out.hpp>
+#include <boost/stopwatches/detail/adaptive_string.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+#define BOOST_STOPWATCHES_STOPWATCH_FORMAT_DEFAULT "%ds\n"
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_stopwatch_formatter {
+ public:
+ typedef std::basic_string<CharT,Traits,Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+ static ostream_type & default_os();
+ static const char_type* default_format();
+ static string_type format(const char_type* s) {
+ string_type res(s);
+ //res += boost::stopwatches::detail::adaptive_string(" tokes %ds\n");
+ res += boost::stopwatches::detail::adaptive_string(" : ");
+ res += default_format();
+ return res;
+ }
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed( ec );
+
+ if ( d < duration_t::zero() ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ boost::io::ios_flags_saver ifs( os );
+ os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+ boost::io::ios_precision_saver ips( os );
+ os.precision( places );
+
+ for ( ; *format; ++format ) {
+ if ( (*format != '%') || (!*(format+1)) || (!std::strchr("d", *(format+1))) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 'd':
+ os << boost::chrono::duration<double>(d).count();
+ break;
+ default:
+ assert(0 && "run_timer internal logic error");
+ }
+ }
+ }
+ }
+ };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_stopwatch_formatter_default_format;
+ template <>
+ struct basic_stopwatch_formatter_default_format<char> {
+ static const char* apply() {return BOOST_STOPWATCHES_STOPWATCH_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_stopwatch_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%ds\n"; }
+ };
+
+#endif
+}
+
+ template <typename CharT,typename Traits, class Alloc>
+ const typename basic_stopwatch_formatter<CharT,Traits,Alloc>::char_type*
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_formatter_default_format<CharT>::apply();
+ }
+
+ template <typename CharT,typename Traits, class Alloc>
+ typename basic_stopwatch_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
+
+ typedef basic_stopwatch_formatter<char> stopwatch_formatter;
+ typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
+
+ } // namespace stopwatches
+} // namespace boost
+
+#define BOOST_STOPWATCHES_STOPWATCH_FORMAT(F) boost::stopwatches::detail::adaptive_string(F " : " BOOST_STOPWATCHES_STOPWATCH_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT boost::stopwatches::stopwatch_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT BOOST_STOPWATCHES_STOPWATCH_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,349 @@
+// boost/stopwatches/stopwatch_reporter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_REPORTER_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_REPORTER_HPP
+
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_STOPWATCHES_ENABLE_WARNINGS)
+#if defined __GNUC__
+#pragma GCC system_header
+#elif defined __SUNPRO_CC
+#pragma disable_warn
+#elif defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#endif
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/stopwatch_scoped.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/chrono/scoped_suspend.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//~ provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+ //~ * format : The output format
+ //~ * places(precission): the number of decimal placess used.
+
+//~ The default places is given by default_places and is 3. The default format is "\n%ts\n", where
+
+ //~ * %t : the result of elapsed() when the reporting is done.
+
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
+
+/* void f1()
+ * {
+ * stopwatch_reporter<stopwatch<> > _;
+ * // ...
+ * }
+ */
+/* void f2()
+ * {
+ * stopwatch<>::reporter _;
+ * // ...
+ * }
+ */
+/* void f3()
+ * {
+ * static stopwatch_reporter<stopwatch_accumulator<> > t;
+ * stopwatch_reporter<stopwatch_accumulator<> >::scoped_run _(t);
+ * // ...
+ * }
+ */
+/* void f4()
+ * {
+ * static stopwatch_accumulator<>::reporter t;
+ * stopwatch_accumulator<>::reporter::scoped_run _(t);
+ * // ...
+ * }
+ */
+//--------------------------------------------------------------------------------------//
+
+ template <class Stopwatch, class Formatter>
+ class basic_stopwatch_reporter : public Stopwatch {
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit basic_stopwatch_reporter( system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+ explicit basic_stopwatch_reporter( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ explicit basic_stopwatch_reporter( const string_type & format,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ explicit basic_stopwatch_reporter( int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ basic_stopwatch_reporter( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : m_places(places), m_os(os), m_format(format), m_reported(false) {
+ if (&ec==&system::throws) ec.clear();
+ }
+
+ ~basic_stopwatch_reporter() {// never throws
+ system::error_code ec;
+ //this->stop(ec);
+ if ( !reported() ) {
+ this->report( ec );
+ }
+ }
+
+
+ inline void report( system::error_code & /*ec*/ = system::throws );
+ bool reported() const { return m_reported; }
+
+
+ typedef stopwatch_runner<basic_stopwatch_reporter<Stopwatch,Formatter> > scoped_run;
+ typedef stopwatch_stopper<basic_stopwatch_reporter<Stopwatch,Formatter> > scoped_stop;
+ typedef stopwatch_suspender<basic_stopwatch_reporter<Stopwatch,Formatter> > scoped_suspend;
+ typedef stopwatch_resumer<basic_stopwatch_reporter<Stopwatch,Formatter> > scoped_resume;
+
+ protected:
+ int m_places;
+ ostream_type & m_os;
+ string_type m_format;
+ bool m_reported;
+
+
+ //basic_stopwatch_reporter(); // = delete;
+ basic_stopwatch_reporter(const basic_stopwatch_reporter&); // = delete;
+ basic_stopwatch_reporter& operator=(const basic_stopwatch_reporter&); // = delete;
+ };
+
+ template <class Stopwatch, class Formatter>
+ void basic_stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
+ chrono::scoped_suspend<typename Stopwatch::clock> _(ec);
+ if (ec) return;
+ if ( m_format.empty() ) m_format = Formatter::default_format();
+
+ m_reported = true;
+ Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec);
+ }
+
+
+ template <class Stopwatch>
+ struct stopwatch_reporter_default_formatter;
+
+ template <class Stopwatch, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ class stopwatch_reporter;
+
+ template <class Stopwatch, class Formatter>
+ struct stopwatch_reporter_default_formatter<stopwatch_reporter<Stopwatch, Formatter> > {
+ typedef Formatter type;
+ };
+
+
+ template <class Stopwatch, class Formatter>
+ class stopwatch_reporter : public basic_stopwatch_reporter<Stopwatch,Formatter> {
+ typedef basic_stopwatch_reporter<Stopwatch,Formatter> base_type;
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit stopwatch_reporter( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit stopwatch_reporter( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit stopwatch_reporter( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit stopwatch_reporter( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ stopwatch_reporter( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ stopwatch_reporter( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ stopwatch_reporter( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ stopwatch_reporter( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ stopwatch_reporter( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ stopwatch_reporter( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+ typedef stopwatch_runner<stopwatch_reporter<Stopwatch,Formatter> > scoped_run;
+ typedef stopwatch_stopper<stopwatch_reporter<Stopwatch,Formatter> > scoped_stop;
+ typedef stopwatch_suspender<stopwatch_reporter<Stopwatch,Formatter> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_reporter<Stopwatch,Formatter> > scoped_resume;
+
+ protected:
+
+
+ //stopwatch_reporter(); // = delete;
+ stopwatch_reporter(const stopwatch_reporter&); // = delete;
+ stopwatch_reporter& operator=(const stopwatch_reporter&); // = delete;
+ };
+
+
+ template <class Stopwatch>
+ struct wstopwatch_reporter_default_formatter;
+
+ template <class Stopwatch, class Formatter=typename wstopwatch_reporter_default_formatter<Stopwatch>::type>
+ class wstopwatch_reporter;
+
+ template <class Stopwatch, class Formatter>
+ struct wstopwatch_reporter_default_formatter<wstopwatch_reporter<Stopwatch, Formatter> > {
+ typedef Formatter type;
+ };
+
+
+ template <class Stopwatch, class Formatter>
+ class wstopwatch_reporter : public basic_stopwatch_reporter<Stopwatch,Formatter> {
+ typedef basic_stopwatch_reporter<Stopwatch,Formatter> base_type;
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit wstopwatch_reporter( system::error_code & ec = system::throws )
+ : base_type(ec) { }
+ explicit wstopwatch_reporter( ostream_type & os,
+ system::error_code & ec = system::throws )
+ : base_type(os, ec) { }
+
+ explicit wstopwatch_reporter( const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(format, ec) { }
+
+ explicit wstopwatch_reporter( int places,
+ system::error_code & ec = system::throws )
+ : base_type(places, ec) { }
+
+ wstopwatch_reporter( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, ec) { }
+
+ wstopwatch_reporter( const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(format, places, ec) { }
+
+ wstopwatch_reporter( ostream_type & os, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, ec) { }
+
+ wstopwatch_reporter( int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(places, format, ec) { }
+
+ wstopwatch_reporter( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws )
+ : base_type(os, format, places, ec) { }
+
+ wstopwatch_reporter( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws )
+ : base_type(os, places, format, ec) { }
+
+ typedef stopwatch_runner<wstopwatch_reporter<Stopwatch,Formatter> > scoped_run;
+ typedef stopwatch_stopper<wstopwatch_reporter<Stopwatch,Formatter> > scoped_stop;
+ typedef stopwatch_suspender<wstopwatch_reporter<Stopwatch,Formatter> > scoped_suspend;
+ typedef stopwatch_resumer<wstopwatch_reporter<Stopwatch,Formatter> > scoped_resume;
+
+ protected:
+
+ //wstopwatch_reporter(); // = delete;
+ wstopwatch_reporter(const wstopwatch_reporter&); // = delete;
+ wstopwatch_reporter& operator=(const wstopwatch_reporter&); // = delete;
+ };
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#if !defined(BOOST_ENABLE_WARNINGS) && !defined(BOOST_STOPWATCHES_ENABLE_WARNINGS)
+#if defined __SUNPRO_CC
+#pragma enable_warn
+#elif defined _MSC_VER
+#pragma warning(pop)
+#endif
+#endif
+
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatch_scoped.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatch_scoped.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,119 @@
+// boost/stopwatches/stopwatch_scoped.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_STOPWATCH_SCOPED_HPP
+#define BOOST_STOPWATCHES_STOPWATCH_SCOPED_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost
+{
+ namespace stopwatches
+ {
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_runner {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_runner(stopwatch & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.start(ec);
+ }
+ ~stopwatch_runner() {
+ system::error_code ec;
+ stopwatch_.stop(ec);
+ }
+#if 0
+ typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
+ {
+ return stopwatch_.elapsed(ec)-stopwatch_.get_storage();
+ }
+#endif
+ private:
+ stopwatch& stopwatch_;
+ stopwatch_runner();//= delete;
+ stopwatch_runner(const stopwatch_runner&); // = delete;
+ stopwatch_runner& operator=(const stopwatch_runner&); // = delete;
+
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_stopper {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_stopper(stopwatch & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.stop(ec);
+ }
+ ~stopwatch_stopper() {
+ system::error_code ec;
+ stopwatch_.start(ec);
+ }
+#if 0
+ typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
+ {
+ return stopwatch_.elapsed(ec)-stopwatch_.get_storage();
+ }
+#endif
+ private:
+ stopwatch& stopwatch_;
+ stopwatch_stopper();//= delete;
+ stopwatch_stopper(const stopwatch_stopper&); // = delete;
+ stopwatch_stopper& operator=(const stopwatch_stopper&); // = delete;
+
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_suspender {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_suspender(stopwatch & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.suspend(ec);
+ }
+ ~stopwatch_suspender() {
+ system::error_code ec;
+ stopwatch_.resume(ec);
+ }
+ private:
+ stopwatch& stopwatch_;
+ stopwatch_suspender(); // = delete;
+ stopwatch_suspender(const stopwatch_suspender&); // = delete;
+ stopwatch_suspender& operator=(const stopwatch_suspender&); // = delete;
+ };
+
+//--------------------------------------------------------------------------------------//
+ template <class Stopwatch> class stopwatch_resumer {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_resumer(stopwatch & a, system::error_code & ec = system::throws)
+ : stopwatch_(a) {
+ stopwatch_.resume(ec);
+ }
+ ~stopwatch_resumer() {
+ system::error_code ec;
+ stopwatch_.suspend(ec);
+ }
+ private:
+ stopwatch& stopwatch_;
+ stopwatch_resumer(); // = delete;
+ stopwatch_resumer(const stopwatch_resumer&); // = delete;
+ stopwatch_resumer& operator=(const stopwatch_resumer&); // = delete;
+ };
+
+
+ } // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif

Added: sandbox/chrono/boost/stopwatches/stopwatches.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/stopwatches.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2010.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/stm for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_STOPWATCHES_STOPWATCHES_HPP
+#define BOOST_STOPWATCHES_STOPWATCHES_HPP
+
+//-----------------------------------------------------------------------------
+#include <boost/stopwatches/t24_hours.hpp>
+#include <boost/stopwatches/t24_hours_formatter.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/stopwatches/stopclock.hpp>
+#include <boost/stopwatches/stopclock_accumulator.hpp>
+#include <boost/stopwatches/scoped_stopclock.hpp>
+#include <boost/stopwatches/stopwatch.hpp>
+#include <boost/stopwatches/stopwatch_accumulator.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_formatter.hpp>
+#include <boost/stopwatches/stopwatch_formatter.hpp>
+#include <boost/stopwatches/stopwatch_reporter.hpp>
+#include <boost/stopwatches/stopwatch_scoped.hpp>
+#include <boost/stopwatches/time_formatter.hpp>
+#include <boost/stopwatches/stopwatch_accumulator_time_formatter.hpp>
+//-----------------------------------------------------------------------------
+
+#endif // BOOST_STOPWATCHES_STOPWATCHES_HPP

Added: sandbox/chrono/boost/stopwatches/t24_hours.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/t24_hours.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,72 @@
+// boost/stopwatches/t24_hours.hpp -----------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_T24_HOURS_HPP
+#define BOOST_STOPWATCHES_T24_HOURS_HPP
+
+#include <boost/chrono/chrono.hpp>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+namespace boost { namespace stopwatches {
+
+class t24_hours {
+ typedef boost::chrono::duration<boost::int_least32_t, ratio<24*3600> > days;
+ typedef boost::chrono::hours hours;
+ typedef boost::chrono::minutes minutes;
+ typedef boost::chrono::seconds seconds;
+ typedef boost::chrono::nanoseconds nanoseconds;
+public:
+ days days_;
+ hours hours_;
+ minutes minutes_;
+ seconds seconds_;
+ nanoseconds nanoseconds_;
+
+ template <class Rep, class Period>
+ static days get_days(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<days>(d);
+ }
+
+ template <class Rep, class Period>
+ static hours get_hours(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<hours>(d % days(1));
+ }
+
+ template <class Rep, class Period>
+ static minutes get_minutes(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<minutes>(d % hours(1));
+ }
+
+ template <class Rep, class Period>
+ static seconds get_seconds(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<seconds>(d % minutes(1));
+ }
+
+ template <class Rep, class Period>
+ static nanoseconds get_nanoseconds(const boost::chrono::duration<Rep, Period>& d) {
+ return boost::chrono::duration_cast<nanoseconds>(d % seconds(1));
+ }
+
+ template <class Rep, class Period>
+ explicit t24_hours(const boost::chrono::duration<Rep, Period>& d)
+ : days_ (get_days(d))
+ , hours_ (get_hours(d))
+ , minutes_ (get_minutes(d))
+ , seconds_ (get_seconds(d))
+ , nanoseconds_ (get_nanoseconds(d))
+ {}
+};
+
+} // namespace stopwatches
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_PROCESS_CLOCK_HPP

Added: sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,167 @@
+// boost/stopwatches/t24_hours_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_T24_HOURS_FORMATTER_HPP
+#define BOOST_STOPWATCHES_T24_HOURS_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/stopwatches/t24_hours.hpp>
+#include <boost/current_function.hpp>
+#include <boost/stopwatches/detail/default_out.hpp>
+#include <boost/stopwatches/detail/adaptive_string.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+#define BOOST_STOPWATCHES_24_HOURS_FORMAT_DEFAULT "%d day(s) %h:%m:%s.%n\n"
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_24_hours_formatter {
+ public:
+
+ typedef std::basic_string<CharT,Traits,Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+ static ostream_type & default_os();
+ static const char_type* default_format();
+ static string_type format(const char_type* s) {
+ string_type res(s);
+ res += boost::stopwatches::detail::adaptive_string(" : ");
+ res += default_format();
+ //res += boost::stopwatches::detail::adaptive_string(" tokes %d day(s) %h:%m:%s.%n\n");
+ return res;
+ }
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_
+ , const char_type* format, int places, ostream_type & os
+ , system::error_code & ec)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed( ec );
+ if (ec) return;
+
+ if ( d < duration_t::zero() ) return;
+
+ boost::io::ios_flags_saver ifs( os );
+ os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+ boost::io::ios_precision_saver ips( os );
+ os.precision( places );
+
+ t24_hours dt(d);
+ for ( ; *format; ++format ) {
+ if ( (*format != '%') || (!*(format+1)) || (!std::strchr("dhmsn", *(format+1))) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 'd':
+ os << dt.days_.count();
+ break;
+ case 'h':
+ {
+ boost::io::ios_flags_saver ifs( os );
+ os.width(2); os.fill('0');
+ os << dt.hours_.count();
+ break;
+ }
+ case 'm':
+ {
+ boost::io::ios_flags_saver ifs( os );
+ os.width(2); os.fill('0');
+ os << dt.minutes_.count();
+ break;
+ }
+ case 's':
+ {
+ boost::io::ios_flags_saver ifs( os );
+ os.width(2); os.fill('0');
+ os << dt.seconds_.count();
+ break;
+ }
+ case 'n':
+ {
+ boost::io::ios_flags_saver ifs( os );
+ os.width(9); os.fill('0');
+ os << dt.nanoseconds_.count();
+ break;
+ }
+ default:
+ assert(0 && "basic_24_hours_formatter internal logic error");
+ }
+ }
+ }
+ }
+ };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_24_hours_formatter_default_format;
+ template <>
+ struct basic_24_hours_formatter_default_format<char> {
+ static const char* apply() {return BOOST_STOPWATCHES_24_HOURS_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_24_hours_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%d day(s) %h:%m:%s.%n\n"; }
+ };
+
+#endif
+}
+
+ template <typename CharT,typename Traits, class Alloc>
+ const typename basic_24_hours_formatter<CharT,Traits,Alloc>::char_type*
+ basic_24_hours_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_24_hours_formatter_default_format<CharT>::apply();
+ }
+
+ template <typename CharT,typename Traits, class Alloc>
+ typename basic_24_hours_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_24_hours_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
+
+ typedef basic_24_hours_formatter<char> t24_hours_formatter;
+ typedef basic_24_hours_formatter<wchar_t> wt24_hours_formatter;
+
+ } // namespace stopwatches
+} // namespace boost
+
+#define BOOST_STOPWATCHES_24_HOURS_FORMAT(F) boost::stopwatches::detail::adaptive_string(F " : " BOOST_STOPWATCHES_24_HOURS_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_STOPWATCHES_24_HOURS_FUNCTION_FORMAT boost::stopwatches::t24_hours_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_STOPWATCHES_24_HOURS_FUNCTION_FORMAT BOOST_STOPWATCHES_24_HOURS_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_T24_HOURS_FORMATTER_HPP

Added: sandbox/chrono/boost/stopwatches/time_formatter.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/stopwatches/time_formatter.hpp 2010-09-02 17:04:18 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,184 @@
+// boost/chrono/time_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_STOPWATCHES_TIME_FORMATTER_HPP
+#define BOOST_STOPWATCHES_TIME_FORMATTER_HPP
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/current_function.hpp>
+#include <boost/stopwatches/detail/default_out.hpp>
+#include <boost/stopwatches/detail/adaptive_string.hpp>
+#include <boost/chrono/suspendible_clock.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/cstdint.hpp>
+#include <string>
+#include <iostream>
+#include <boost/io/ios_state.hpp>
+#include <cstring>
+#include <cassert>
+
+#include <boost/config/abi_prefix.hpp> // must be the last #include
+
+
+#define BOOST_STOPWATCHES_TIME_FORMAT_DEFAULT "real %rs, cpu %cs (%p%), user %us, system %ss\n"
+
+
+namespace boost { namespace stopwatches {
+
+//--------------------------------------------------------------------------------------//
+//--------------------------------------------------------------------------------------//
+
+
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_time_formatter {
+ public:
+
+ typedef std::basic_string<CharT,Traits,Alloc> string_type;
+ typedef CharT char_type;
+ typedef std::basic_ostream<CharT,Traits> ostream_type;
+
+ static ostream_type & default_os();
+ static const char_type* default_format();
+ static string_type format(const char_type* s) {
+ string_type res(s);
+ res += boost::stopwatches::detail::adaptive_string(" : ");
+ res += default_format();
+ //res += boost::stopwatches::detail::adaptive_string(" spent real %rs, cpu %cs (%p%), user %us, system %ss\n");
+ return res;
+ }
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( typename Stopwatch::duration::rep const & times
+ , const char_type* format, int places, ostream_type & os
+ , system::error_code & ec
+ )
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ if (&ec != &system::throws) ec.clear();
+ typedef typename Stopwatch::duration duration;
+ typedef typename duration::rep rep;
+ if ( times.real < 0 ) return;
+ if ( places > 9 )
+ places = 9; // sanity check
+ else if ( places < 0 )
+ places = 0;
+
+ boost::io::ios_flags_saver ifs( os );
+ os.setf( std::ios_base::fixed, std::ios_base::floatfield );
+ boost::io::ios_precision_saver ips( os );
+ os.precision( places );
+
+ chrono::nanoseconds total = chrono::nanoseconds(times.system + times.user);
+
+ for ( ; *format; ++format )
+ {
+ if ( (*format != '%') || (!*(format+1)) || (!std::strchr("rcpus", *(format+1))) )
+ os << *format;
+ else
+ {
+ ++format;
+ switch ( *format )
+ {
+ case 'r':
+ os << boost::chrono::duration<double>(chrono::nanoseconds(times.real)).count();
+ break;
+ case 'u':
+ os << boost::chrono::duration<double>(chrono::nanoseconds(times.user)).count();
+ break;
+ case 's':
+ os << boost::chrono::duration<double>(chrono::nanoseconds(times.system)).count();
+ break;
+ case 'c':
+ os << boost::chrono::duration<double>(total).count();
+ break;
+ case 'p':
+ {
+ boost::io::ios_precision_saver ips( os );
+ os.precision( 1 );
+ if ( times.real && total.count() )
+ os << boost::chrono::duration<double>(total).count()
+ /boost::chrono::duration<double>(chrono::nanoseconds(times.real)).count() * 100.0;
+ else
+ os << 0.0;
+ }
+ break;
+ default:
+ assert(0 && "basic_time_formatter internal logic error");
+ }
+ }
+ }
+ }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_
+ , const char_type* format, int places, ostream_type & os
+ , system::error_code & ec)
+ // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
+ // be as low as 10, although will be 15 for many common platforms.
+ {
+ typedef typename Stopwatch::duration duration;
+ typedef typename duration::rep rep;
+ duration d = stopwatch_.elapsed( ec );
+ if (ec) return;
+ rep times=d.count();
+ show_time<Stopwatch>(times, format, places, os, ec);
+ }
+ };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_time_formatter_default_format;
+ template <>
+ struct basic_time_formatter_default_format<char> {
+ static const char* apply() {return BOOST_STOPWATCHES_TIME_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_time_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"real %rs, cpu %cs (%p%), user %us, system %ss\n"; }
+ };
+
+#endif
+}
+
+ template <typename CharT,typename Traits, class Alloc>
+ const typename basic_time_formatter<CharT,Traits,Alloc>::char_type*
+ basic_time_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_time_formatter_default_format<CharT>::apply();
+ }
+
+ template <typename CharT,typename Traits, class Alloc>
+ typename basic_time_formatter<CharT,Traits,Alloc>::ostream_type &
+ basic_time_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
+
+ typedef basic_time_formatter<char> time_formatter;
+ typedef basic_time_formatter<wchar_t> wtime_formatter;
+
+ } // namespace stopwatches
+} // namespace boost
+
+#define BOOST_STOPWATCHES_TIME_FORMAT(F) boost::stopwatches::detail::adaptive_string(F " : " BOOST_STOPWATCHES_TIME_FORMAT_DEFAULT)
+#ifdef __GNUC__
+#define BOOST_STOPWATCHES_TIME_FUNCTION_FORMAT boost::stopwatches::time_formatter::format(BOOST_CURRENT_FUNCTION)
+#else
+#define BOOST_STOPWATCHES_TIME_FUNCTION_FORMAT BOOST_STOPWATCHES_TIME_FORMAT(BOOST_CURRENT_FUNCTION)
+#endif
+
+#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
+
+#endif // BOOST_STOPWATCHES_TIME_FORMATTER_HPP


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk