|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r59070 - sandbox/chrono/boost/chrono
From: vicente.botet_at_[hidden]
Date: 2010-01-16 07:54:59
Author: viboes
Date: 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
New Revision: 59070
URL: http://svn.boost.org/trac/boost/changeset/59070
Log:
Boost.Chrono: Version 0.3.0,
* Code cleanup
* Added stopclock shortcuts
* revert to old process_times.hpp
Added:
sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp
- copied, changed from r58947, /sandbox/chrono/boost/chrono/process_clocks.hpp
sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp
- copied, changed from r58947, /sandbox/chrono/boost/chrono/process_stopwatches.hpp
sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp
- copied, changed from r58947, /sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp
Removed:
sandbox/chrono/boost/chrono/process_clocks.hpp
sandbox/chrono/boost/chrono/process_stopwatches.hpp
sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp
sandbox/chrono/boost/chrono/timer_accumulator.hpp
Text files modified:
sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp | 4
sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp | 5 -
sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp | 2
sandbox/chrono/boost/chrono/chrono.hpp | 10 ++--
sandbox/chrono/boost/chrono/digital_time.hpp | 4
sandbox/chrono/boost/chrono/digital_time_formatter.hpp | 14 +++---
sandbox/chrono/boost/chrono/process_cpu_clocks.hpp | 12 ++--
sandbox/chrono/boost/chrono/process_times.hpp | 88 +++++++++++++++++----------------------
sandbox/chrono/boost/chrono/stopclock.hpp | 32 +++++++++-----
sandbox/chrono/boost/chrono/stopwatch.hpp | 26 +++++-----
sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp | 34 +++++++-------
sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp | 10 ++--
sandbox/chrono/boost/chrono/stopwatch_formatter.hpp | 10 ++--
sandbox/chrono/boost/chrono/stopwatch_reporter.hpp | 50 +++++++++++-----------
sandbox/chrono/boost/chrono/stopwatch_scoped.hpp | 18 ++++----
sandbox/chrono/boost/chrono/time_formatter.hpp | 16 +++---
16 files changed, 166 insertions(+), 169 deletions(-)
Copied: sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp (from r58947, /sandbox/chrono/boost/chrono/process_clocks.hpp)
==============================================================================
--- /sandbox/chrono/boost/chrono/process_clocks.hpp (original)
+++ sandbox/chrono/boost/chrono/TBRprocess_clocks.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost process_clocks.hpp -----------------------------------------------------------//
+// boost/chrono/process_clocks.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 1994, 2007, 2008
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -45,7 +45,7 @@
process_clocks::time_point user; // user cpu time
process_clocks::time_point system; // system cpu time
};
-
+
static void now( durations & times,
system::error_code & ec = system::throws );
static void now( time_points & times,
Copied: sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp (from r58947, /sandbox/chrono/boost/chrono/process_stopwatches.hpp)
==============================================================================
--- /sandbox/chrono/boost/chrono/process_stopwatches.hpp (original)
+++ sandbox/chrono/boost/chrono/TBRprocess_stopwatches.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost process_times.hpp -----------------------------------------------------------//
+// boost/chrono/process_stopwatches.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 1994, 2007, 2008
@@ -13,9 +13,6 @@
#include <boost/chrono/chrono.hpp>
#include <boost/chrono/process_clocks.hpp>
#include <boost/system/error_code.hpp>
-//#include <boost/cstdint.hpp>
-//#include <string>
-//#include <ostream>
#include <boost/config/abi_prefix.hpp> // must be the last #include
Copied: sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp (from r58947, /sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp)
==============================================================================
--- /sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/TBRprocess_stopwatches_reporter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost process_times.hpp -----------------------------------------------------------//
+// boost/chrono/process_stopwatches_reporter.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 1994, 2007, 2008
Modified: sandbox/chrono/boost/chrono/chrono.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/chrono.hpp (original)
+++ sandbox/chrono/boost/chrono/chrono.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -2,7 +2,7 @@
// Copyright 2008 Howard Hinnant
// Copyright 2008 Beman Dawes
-// Copyright 2009 Vicente J. Botet Escriba
+// 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
@@ -169,7 +169,7 @@
: duration_divide_imp<duration<Rep1, Period>, Rep2>
{
};
-
+
///
template <class Duration, class Rep, bool = is_duration<Rep>::value>
struct duration_modulo_result
@@ -180,7 +180,7 @@
bool = (
//boost::is_convertible<typename Duration::rep,
//typename common_type<typename Duration::rep, Rep2>::type>::value
- //&&
+ //&&
boost::is_convertible<Rep2,
typename common_type<typename Duration::rep, Rep2>::type>::value
)
@@ -200,7 +200,7 @@
: duration_modulo_imp<duration<Rep1, Period>, Rep2>
{
};
-
+
} // namespace detail
} // namespace chrono
@@ -697,7 +697,7 @@
r %= static_cast<CR>(s);
return r;
}
-
+
template <class Rep1, class Period1, class Rep2, class Period2>
typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs) {
Modified: sandbox/chrono/boost/chrono/digital_time.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time.hpp (original)
+++ sandbox/chrono/boost/chrono/digital_time.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost digital_time.hpp -----------------------------------------------------------//
+// boost/chrono/digital_time.hpp -----------------------------------------------------------//
// Copyright 2010 Vicente J. Botet Escriba
@@ -53,7 +53,7 @@
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 digital_time(const boost::chrono::duration<Rep, Period>& d)
: days_ (get_days(d))
Modified: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,6 +1,6 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/digital_time_formatter.hpp ------------------------------------------------------------//
-// Copyright 2009-2010 Vicente J. Botet Escriba
+// 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)
@@ -35,7 +35,7 @@
static const char * default_format;
static int default_places() { return m_default_places; }
- template <class Stopwatch >
+ template <class Stopwatch >
static void show_time( Stopwatch & stopwatch_
, const char * format, int places, std::ostream & os
, system::error_code & ec)
@@ -44,7 +44,7 @@
{
typedef typename Stopwatch::duration duration;
duration d = stopwatch_.elapsed( ec );
-
+
if ( d < duration(0) ) return;
boost::io::ios_flags_saver ifs( os );
@@ -62,7 +62,7 @@
case 'd':
os << dt.days_.count();
break;
- case 'h':
+ case 'h':
{
boost::io::ios_flags_saver ifs( os );
os.width(2); os.fill('0');
@@ -96,9 +96,9 @@
}
}
}
- };
+ };
const char * digital_time_formatter::default_format ="\n%d days(s) %h:%m:%s.%n\n";
-
+
std::ostream & digital_time_formatter::m_cout() { return std::cout; }
} // namespace chrono
Deleted: sandbox/chrono/boost/chrono/process_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_clocks.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,61 +0,0 @@
-// boost process_clocks.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-// 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_PROCESS_CLOCKS_HPP
-#define BOOST_PROCESS_CLOCKS_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-//#include <boost/cstdint.hpp>
-//#include <string>
-//#include <ostream>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
- class BOOST_CHRONO_DECL process_clocks
- {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_clocks> time_point;
- static const bool is_monotonic = true;
-
- struct durations
- {
- process_clocks::duration real; // real (i.e wall clock) time
- process_clocks::duration user; // user cpu time
- process_clocks::duration system; // system cpu time
- };
- struct time_points
- {
- process_clocks::time_point real; // real (i.e wall clock) time
- process_clocks::time_point user; // user cpu time
- process_clocks::time_point system; // system cpu time
- };
-
- static void now( durations & times,
- system::error_code & ec = system::throws );
- static void now( time_points & times,
- system::error_code & ec = system::throws );
- };
-
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP
Modified: sandbox/chrono/boost/chrono/process_cpu_clocks.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_cpu_clocks.hpp (original)
+++ sandbox/chrono/boost/chrono/process_cpu_clocks.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost process_cpu_clocks.hpp -----------------------------------------------------------//
+// boost/chrono/process_cpu_clocks.hpp -----------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -56,7 +56,7 @@
public:
struct times : arithmetic<times>, less_than_comparable<times>
{
- times()
+ times()
: real(0)
, user(0)
, system(0){}
@@ -67,7 +67,7 @@
: real(r)
, user(u)
, system(s){}
-
+
process_real_cpu_clock::rep real; // real (i.e wall clock) time
process_user_cpu_clock::rep user; // user cpu time
process_system_cpu_clock::rep system; // system cpu time
@@ -77,7 +77,7 @@
user==rhs.user &&
system==rhs.system);
}
-
+
times operator+=(times const& rhs) {
real+=rhs.real;
user+=rhs.user;
@@ -102,7 +102,7 @@
system/=rhs.system;
return *this;
}
- bool operator<(times const & rhs) const {
+ bool operator<(times const & rhs) const {
if (real < rhs.real) return true;
if (real > rhs.real) return false;
if (user < rhs.user) return true;
@@ -138,7 +138,7 @@
(std::numeric_limits<process_system_cpu_clock::rep>::min)());
}
};
-
+
} // namespace chrono
} // namespace boost
Deleted: sandbox/chrono/boost/chrono/process_stopwatches.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_stopwatches.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,70 +0,0 @@
-// boost process_times.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-
-// 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_PROCESS_STOPWATCHED_HPP
-#define BOOST_PROCESS_STOPWATCHED_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/chrono/process_clocks.hpp>
-#include <boost/system/error_code.hpp>
-//#include <boost/cstdint.hpp>
-//#include <string>
-//#include <ostream>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
-
- class BOOST_CHRONO_DECL process_stopwatches
- // BOOST_CHRONO_DECL is required to quiet compiler warnings even though
- // process_stopwatches has no dynamically linked members, because process_stopwatches is
- // used as a base class for process_stopwatches_reporter, which does have dynamically linked members.
- {
- public:
-
- typedef process_clocks clock;
- typedef process_clocks::duration duration;
- typedef process_clocks::time_point time_point;
-
- explicit process_stopwatches( system::error_code & ec = system::throws )
- {
- start(ec);
- }
-
- ~process_stopwatches() {} // never throws
-
- void start( system::error_code & ec = system::throws )
- {
- process_clocks::now( m_start, ec );
- }
-
- void elapsed( process_clocks::durations & times, system::error_code & ec = system::throws )
- {
- process_clocks::durations end;
- process_clocks::now( end, ec );
- times.real = end.real - m_start.real;
- times.user = end.user - m_start.user;
- times.system = end.system - m_start.system;
- }
-
- protected:
- process_clocks::durations m_start;
- };
-
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP
Deleted: sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_stopwatches_reporter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,98 +0,0 @@
-// boost process_times.hpp -----------------------------------------------------------//
-
-// Copyright Beman Dawes 1994, 2007, 2008
-
-// 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_PROCESS_STOPWATCHED_REPORTER_HPP
-#define BOOST_PROCESS_STOPWATCHED_REPORTER_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-#include <boost/chrono/process_clocks.hpp>
-#include <boost/chrono/process_stopwatches.hpp>
-#include <boost/cstdint.hpp>
-#include <string>
-#include <ostream>
-
-#include <boost/config/abi_prefix.hpp> // must be the last #include
-
-namespace boost
-{
- namespace chrono
- {
-
- class BOOST_CHRONO_DECL process_stopwatches_reporter : public process_stopwatches
- {
- // every function making use of inlined functions of class string are not inlined to avoid DLL issues
- public:
-
- // each constructor form has two overloads to avoid a visible default to
- // std::cout, which in turn would require including <iostream>, with its
- // high associated cost, even when the standard streams are not used.
-
- explicit process_stopwatches_reporter( system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( const std::string & format,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
- int places, system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( int places,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places,
- system::error_code & ec = system::throws );
-
- explicit process_stopwatches_reporter( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
-
- ~process_stopwatches_reporter() // never throws
- {
- system::error_code ec;
- if ( !reported() ) report( ec );
- }
-
- void start( system::error_code & ec = system::throws )
- {
- m_reported = false;
- process_stopwatches::start( ec );
- }
-
- void report( system::error_code & ec = system::throws );
-
- void test_report( duration real_, duration user_, duration system_ );
-
- bool reported() const { return m_reported; }
-
- static int default_places() { return m_default_places; }
-
- private:
- int m_places;
- std::ostream & m_os;
- std::string m_format;
- bool m_reported;
-
- static std::ostream & m_cout();
- static const int m_default_places = 3;
- };
-
- typedef process_stopwatches_reporter run_timer; // backward comppatibility
-
- } // namespace chrono
-} // namespace boost
-
-#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
-
-#endif // BOOST_PROCESS_TIMES_HPP
Modified: sandbox/chrono/boost/chrono/process_times.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/process_times.hpp (original)
+++ sandbox/chrono/boost/chrono/process_times.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,6 +1,7 @@
-// boost process_times.hpp -----------------------------------------------------------//
+// boost/chrono/process_times.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 1994, 2007, 2008
+// Copyright Vicente J Botet Escriba 2009-2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
@@ -11,10 +12,6 @@
#define BOOST_PROCESS_TIMES_HPP
#include <boost/chrono/chrono.hpp>
-#include <boost/chrono/process_clocks.hpp>
-#include <boost/chrono/process_stopwatches.hpp>
-#include <boost/chrono/process_stopwatches_reporter.hpp>
-
#include <boost/system/error_code.hpp>
#include <boost/cstdint.hpp>
#include <string>
@@ -27,30 +24,29 @@
namespace chrono
{
//--------------------------------------------------------------------------------------//
-// process_clocks //
+// process_clock //
//--------------------------------------------------------------------------------------//
-#if 0
- class BOOST_CHRONO_DECL process_clocks
+ class BOOST_CHRONO_DECL process_clock
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
- typedef chrono::time_point<process_clocks> time_point;
+ typedef chrono::time_point<process_clock> time_point;
static const bool is_monotonic = true;
struct durations
{
- process_clocks::duration real; // real (i.e wall clock) time
- process_clocks::duration user; // user cpu time
- process_clocks::duration system; // system cpu time
+ process_clock::duration real; // real (i.e wall clock) time
+ process_clock::duration user; // user cpu time
+ process_clock::duration system; // system cpu time
};
struct time_points
{
- process_clocks::time_point real; // real (i.e wall clock) time
- process_clocks::time_point user; // user cpu time
- process_clocks::time_point system; // system cpu time
+ process_clock::time_point real; // real (i.e wall clock) time
+ process_clock::time_point user; // user cpu time
+ process_clock::time_point system; // system cpu time
};
static void now( durations & times,
@@ -58,46 +54,44 @@
static void now( time_points & times,
system::error_code & ec = system::throws );
};
-#endif
+
//--------------------------------------------------------------------------------------//
// process_times //
//--------------------------------------------------------------------------------------//
- typedef process_clocks process_clock;
- typedef process_clocks::durations process_times;
+ typedef process_clock::durations process_times;
//--------------------------------------------------------------------------------------//
-// process_stopwatches //
+// process_timer //
//--------------------------------------------------------------------------------------//
-#if 0
- class BOOST_CHRONO_DECL process_stopwatches
+ class BOOST_CHRONO_DECL process_timer
// BOOST_CHRONO_DECL is required to quiet compiler warnings even though
- // process_stopwatches has no dynamically linked members, because process_stopwatches is
- // used as a base class for process_stopwatches_reporter, which does have dynamically linked members.
+ // process_timer has no dynamically linked members, because process_timer is
+ // used as a base class for run_timer, which does have dynamically linked members.
{
public:
- typedef process_clocks clock;
- typedef process_clocks::duration duration;
- typedef process_clocks::time_point time_point;
+ typedef process_clock clock;
+ typedef process_clock::duration duration;
+ typedef process_clock::time_point time_point;
- explicit process_stopwatches( system::error_code & ec = system::throws )
+ explicit process_timer( system::error_code & ec = system::throws )
{
start(ec);
}
- ~process_stopwatches() {} // never throws
+ ~process_timer() {} // never throws
void start( system::error_code & ec = system::throws )
{
- process_clocks::now( m_start, ec );
+ process_clock::now( m_start, ec );
}
void elapsed( process_times & times, system::error_code & ec = system::throws )
{
process_times end;
- process_clocks::now( end, ec );
+ process_clock::now( end, ec );
times.real = end.real - m_start.real;
times.user = end.user - m_start.user;
times.system = end.system - m_start.system;
@@ -106,14 +100,12 @@
protected:
process_times m_start;
};
-#endif
- typedef process_stopwatches process_timer; // backward comppatibility
+
//--------------------------------------------------------------------------------------//
-// process_stopwatches_reporter //
+// run_timer //
//--------------------------------------------------------------------------------------//
-#if 0
- class BOOST_CHRONO_DECL process_stopwatches_reporter : public process_stopwatches
+ class BOOST_CHRONO_DECL run_timer : public process_timer
{
// every function making use of inlined functions of class string are not inlined to avoid DLL issues
public:
@@ -122,31 +114,31 @@
// std::cout, which in turn would require including <iostream>, with its
// high associated cost, even when the standard streams are not used.
- explicit process_stopwatches_reporter( system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os,
+ explicit run_timer( system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( const std::string & format,
+ explicit run_timer( const std::string & format,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
+ run_timer( std::ostream & os, const std::string & format,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( const std::string & format, int places,
+ run_timer( const std::string & format, int places,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, const std::string & format,
+ run_timer( std::ostream & os, const std::string & format,
int places, system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( int places,
+ explicit run_timer( int places,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places,
+ run_timer( std::ostream & os, int places,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( int places, const std::string & format,
+ run_timer( int places, const std::string & format,
system::error_code & ec = system::throws );
- explicit process_stopwatches_reporter( std::ostream & os, int places, const std::string & format,
+ run_timer( std::ostream & os, int places, const std::string & format,
system::error_code & ec = system::throws );
- ~process_stopwatches_reporter() // never throws
+ ~run_timer() // never throws
{
system::error_code ec;
if ( !reported() ) report( ec );
@@ -155,7 +147,7 @@
void start( system::error_code & ec = system::throws )
{
m_reported = false;
- process_stopwatches::start( ec );
+ process_timer::start( ec );
}
void report( system::error_code & ec = system::throws );
@@ -175,8 +167,6 @@
static std::ostream & m_cout();
static const int m_default_places = 3;
};
-#endif
- typedef process_stopwatches_reporter run_timer; // backward comppatibility
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopclock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopclock.hpp (original)
+++ sandbox/chrono/boost/chrono/stopclock.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopclock.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -13,6 +13,7 @@
#include <boost/chrono/stopwatch_reporter.hpp>
#include <boost/chrono/stopwatch.hpp>
#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/chrono/time_formatter.hpp>
#include <boost/config/abi_prefix.hpp> // must be the last #include
@@ -26,19 +27,19 @@
//~ 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.
+ //~ * %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.
+//~ The time is given using the suffix "s" following the System International d'Unites Std.
/* void f1()
* {
* stopclock<> _;
* // ...
- * }
+ * }
*/
//--------------------------------------------------------------------------------------//
- template <class Clock=process_cpu_clock, class Stopwatch=stopwatch<Clock>, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ template <class Clock=process_cpu_clock, class Stopwatch=stopwatch<Clock>, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
class stopclock : public stopwatch_reporter<Stopwatch, Formatter> {
typedef stopwatch_reporter<Stopwatch, Formatter> base_type;
public:
@@ -55,7 +56,7 @@
explicit stopclock( int places,
system::error_code & ec = system::throws )
: base_type(places, ec) { }
-
+
stopclock( std::ostream & os, const std::string & format,
system::error_code & ec = system::throws )
: base_type(os, format, ec) { }
@@ -63,7 +64,7 @@
stopclock( const std::string & format, int places,
system::error_code & ec = system::throws )
: base_type(format, places, ec) { }
-
+
stopclock( std::ostream & os, int places,
system::error_code & ec = system::throws )
: base_type(os, places, ec) { }
@@ -71,7 +72,7 @@
stopclock( int places, const std::string & format,
system::error_code & ec = system::throws )
: base_type(places, format, ec) { }
-
+
stopclock( std::ostream & os, const std::string & format, int places,
system::error_code & ec = system::throws )
: base_type(os, format, places, ec) { }
@@ -80,12 +81,21 @@
system::error_code & ec = system::throws )
: base_type(os, places, format, ec) { }
-
+
typedef typename base_type::scoped_run scoped_run;
typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
+ typedef typename base_type::scoped_resume scoped_resume;
};
-
+
+ typedef stopclock< boost::chrono::system_clock > system_stopclock;
+ #ifdef BOOST_CHRONO_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;
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -41,12 +41,12 @@
template <class Clock=high_resolution_clock>
class stopwatch;
-
- template <class Clock>
+
+ template <class Clock>
struct stopwatch_reporter_default_formatter<stopwatch<Clock> > {
typedef stopwatch_formatter type;
};
-
+
struct dont_start_t{};
static const dont_start_t dont_start = {};
template <class Clock>
@@ -86,7 +86,7 @@
if (ec) return duration(0);
partial_ += tmp - start_;
duration frozen= partial_;
- partial_=duration(0);
+ partial_=duration(0);
running_=false;
return frozen;
} else {
@@ -101,7 +101,7 @@
if (running_&&(--level_==0)) {
partial_ += tmp - start_;
frozen = partial_;
- partial_=duration(0);
+ partial_=duration(0);
} else {
frozen = duration(0);
running_=true;
@@ -138,7 +138,7 @@
return time_point();
}
}
-
+
duration elapsed( system::error_code & ec = system::throws )
{
return clock::now( ec ) - start_;
@@ -152,9 +152,9 @@
typedef stopwatch_runner<stopwatch<Clock> > scoped_run;
typedef stopwatch_suspender<stopwatch<Clock> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
- typedef stopwatch_reporter<stopwatch<Clock> > reporter;
-
+ typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch<Clock> > reporter;
+
private:
bool running_;
bool suspended_;
@@ -162,7 +162,7 @@
std::size_t level_;
duration partial_;
std::size_t suspend_level_;
-
+
};
//--------------------------------------------------------------------------------------//
@@ -172,8 +172,8 @@
#endif
typedef boost::chrono::stopwatch< boost::chrono::high_resolution_clock > high_resolution_stopwatch;
-
-
+
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch_accumulator.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -46,23 +46,23 @@
//--------------------------------------------------------------------------------------//
// forward declaration
- template <class Clock=high_resolution_clock,
+ template <class Clock=high_resolution_clock,
class Accumulator=accumulators::accumulator_set<typename Clock::duration::rep,
- accumulators::features<
- accumulators::tag::count,
- accumulators::tag::sum,
- accumulators::tag::min,
- accumulators::tag::max,
+ accumulators::features<
+ accumulators::tag::count,
+ accumulators::tag::sum,
+ accumulators::tag::min,
+ accumulators::tag::max,
accumulators::tag::mean >
- >
+ >
>
class stopwatch_accumulator;
-
- template <class Clock>
+
+ template <class Clock>
struct stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock> > {
typedef stopwatch_accumulator_formatter type;
};
-
+
//--------------------------------------------------------------------------------------//
template <class Clock, class Accumulator>
class stopwatch_accumulator
@@ -75,7 +75,7 @@
stopwatch_accumulator( )
: running_(false), partial_(0)
- {
+ {
}
std::pair<duration, time_point> restart( system::error_code & ec = system::throws ) {
@@ -84,7 +84,7 @@
if (running_&&(--level_==0)) {
partial_ += tmp - start_;
accumulated_(partial_.count());
- partial_=duration(0);
+ partial_=duration(0);
} else {
running_=true;
}
@@ -172,8 +172,8 @@
typedef stopwatch_runner<stopwatch_accumulator<Clock> > scoped_run;
typedef stopwatch_suspender<stopwatch_accumulator<Clock> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch_accumulator<Clock> > scoped_resume;
- typedef stopwatch_reporter<stopwatch_accumulator<Clock> > reporter;
+ typedef stopwatch_resumer<stopwatch_accumulator<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch_accumulator<Clock> > reporter;
private:
bool running_;
bool suspended_;
@@ -192,8 +192,8 @@
typedef boost::chrono::stopwatch_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopwatch_accumulator;
//--------------------------------------------------------------------------------------//
-
-
+
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch_accumulator_formatter.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -42,7 +42,7 @@
static const char * default_format;
static int default_places() { return m_default_places; }
- template <class Stopwatch >
+ template <class Stopwatch >
static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & 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.
@@ -50,7 +50,7 @@
typedef typename Stopwatch::accumulator accumulator;
typedef typename Stopwatch::duration duration;
accumulator& acc = stopwatch_.accumulated();
-
+
//if ( d < duration(0) ) return;
if ( places > 9 )
places = 9; // sanity check
@@ -92,10 +92,10 @@
}
}
}
- };
+ };
const char * stopwatch_accumulator_formatter::default_format ="\n%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
std::ostream & stopwatch_accumulator_formatter::m_cout() { return std::cout; }
-
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch_formatter.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -35,14 +35,14 @@
static const char * default_format;
static int default_places() { return m_default_places; }
- template <class Stopwatch >
+ template <class Stopwatch >
static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & 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;
duration d = stopwatch_.elapsed( ec );
-
+
if ( d < duration(0) ) return;
if ( places > 9 )
places = 9; // sanity check
@@ -69,9 +69,9 @@
}
}
}
- };
+ };
const char * stopwatch_formatter::default_format ="\n%ds\n";
-
+
std::ostream & stopwatch_formatter::m_cout() { return std::cout; }
} // namespace chrono
Modified: sandbox/chrono/boost/chrono/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_reporter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch_reporter.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -32,54 +32,54 @@
//~ 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.
+ //~ * %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.
+//~ 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>
+
+ template <class Stopwatch>
struct stopwatch_reporter_default_formatter {
typename Stopwatch::formatter type;
};
- template <class Stopwatch, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ 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 typename stopwatch_reporter_default_formatter<Stopwatch>::type type;
};
-
-
- template <class Stopwatch, class Formatter>
+
+
+ template <class Stopwatch, class Formatter>
class stopwatch_reporter : public Stopwatch {
public:
explicit stopwatch_reporter( system::error_code & ec = system::throws )
@@ -103,15 +103,15 @@
stopwatch_reporter( const std::string & format, int places,
system::error_code & ec = system::throws )
: m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
-
+
stopwatch_reporter( std::ostream & os, int places,
system::error_code & ec = system::throws )
: m_places(places), m_os(os), m_format(Formatter::default_format), m_reported(false) { }
-
+
stopwatch_reporter( int places, const std::string & format,
system::error_code & ec = system::throws )
: m_places(places), m_os(Formatter::m_cout()), m_format(format), m_reported(false) { }
-
+
stopwatch_reporter( std::ostream & os, const std::string & format, int places,
system::error_code & ec = system::throws )
: m_places(places), m_os(os), m_format(format), m_reported(false) { }
@@ -131,25 +131,25 @@
inline void report( system::error_code & ec = system::throws );
bool reported() const { return m_reported; }
-
-
+
+
typedef stopwatch_runner<stopwatch_reporter<Stopwatch> > scoped_run;
typedef stopwatch_suspender<stopwatch_reporter<Stopwatch> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
-
+ typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
+
private:
int m_places;
std::ostream & m_os;
std::string m_format;
bool m_reported;
-
+
//stopwatch_reporter(); // = delete;
stopwatch_reporter(const stopwatch_reporter&); // = delete;
stopwatch_reporter& operator=(const stopwatch_reporter&); // = delete;
};
-
- template <class Stopwatch, class Formatter>
+
+ template <class Stopwatch, class Formatter>
void stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
m_reported = true;
if ( m_format.empty() ) m_format = Formatter::default_format;
@@ -157,7 +157,7 @@
//typename Stopwatch::duration d = this->elapsed( ec );
if ( &ec == &system::throws ) {
Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec);
- } else {// non-throwing
+ } else {// non-throwing
try {
Formatter::show_time( *this, m_format.c_str(), m_places, m_os, ec );
ec = system::error_code();
@@ -166,7 +166,7 @@
//ec = error_code( EIO, errno_ecat );
}
}
-
+
}
Modified: sandbox/chrono/boost/chrono/stopwatch_scoped.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_scoped.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_scoped.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/stopwatch_scoped.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -24,7 +24,7 @@
template <class Stopwatch> class stopwatch_runner {
public:
typedef Stopwatch stopwatch_type;
- stopwatch_runner(stopwatch_type & a, system::error_code & ec = system::throws)
+ stopwatch_runner(stopwatch_type & a, system::error_code & ec = system::throws)
: stopwatch_(a) {
stopwatch_.start(ec);
}
@@ -32,12 +32,12 @@
system::error_code ec;
stopwatch_.stop(ec);
}
-#if 0
+#if 0
typename Stopwatch::duration elapsed(system::error_code & ec = system::throws)
{
return stopwatch_.elapsed(ec)-stopwatch_.accumulated();
}
-#endif
+#endif
private:
stopwatch_type& stopwatch_;
stopwatch_runner();//= delete;
@@ -50,7 +50,7 @@
template <class Stopwatch> class stopwatch_suspender {
public:
typedef Stopwatch stopwatch_type;
- stopwatch_suspender(stopwatch_type & a, system::error_code & ec = system::throws)
+ stopwatch_suspender(stopwatch_type & a, system::error_code & ec = system::throws)
: stopwatch_(a) {
stopwatch_.suspend(ec);
}
@@ -69,7 +69,7 @@
template <class Stopwatch> class stopwatch_resumer {
public:
typedef Stopwatch stopwatch_type;
- stopwatch_resumer(stopwatch_type & a, system::error_code & ec = system::throws)
+ stopwatch_resumer(stopwatch_type & a, system::error_code & ec = system::throws)
: stopwatch_(a) {
stopwatch_.resume(ec);
}
@@ -81,10 +81,10 @@
stopwatch_type& stopwatch_;
stopwatch_resumer(); // = delete;
stopwatch_resumer(const stopwatch_resumer&); // = delete;
- stopwatch_resumer& operator=(const stopwatch_resumer&); // = delete;
+ stopwatch_resumer& operator=(const stopwatch_resumer&); // = delete;
};
-
-
+
+
} // namespace chrono
} // namespace boost
Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
@@ -1,4 +1,4 @@
-// boost/chrono/timer.hpp ------------------------------------------------------------//
+// boost/chrono/time_formatter.hpp ------------------------------------------------------------//
// Copyright 2009-2010 Vicente J. Botet Escriba
@@ -35,7 +35,7 @@
static const char * default_format;
static int default_places() { return m_default_places; }
- template <class Stopwatch >
+ template <class Stopwatch >
static void show_time( Stopwatch & stopwatch_
, const char * format, int places, std::ostream & os
, system::error_code & ec)
@@ -45,7 +45,7 @@
typedef typename Stopwatch::duration duration;
typedef typename duration::rep rep;
duration d = stopwatch_.elapsed( ec );
- rep times=d.count();
+ rep times=d.count();
if ( times.real < 0 ) return;
if ( places > 9 )
places = 9; // sanity check
@@ -98,17 +98,17 @@
}
}
- };
+ };
const char * time_formatter::default_format = "\nreal %rs, cpu %cs (%p%), user %us, system %ss\n";
-
+
std::ostream & time_formatter::m_cout() { return std::cout; }
-
- template <>
+
+ template <>
struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
typedef time_formatter type;
};
-
+
} // namespace chrono
} // namespace boost
Deleted: sandbox/chrono/boost/chrono/timer_accumulator.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/timer_accumulator.hpp 2010-01-16 07:54:57 EST (Sat, 16 Jan 2010)
+++ (empty file)
@@ -1,309 +0,0 @@
-// boost/chrono/timer.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_CHRONO_TIMER_ACCUMULATOR_HPP
-#define BOOST_CHRONO_TIMER_ACCUMULATOR_HPP
-
-#include <boost/chrono/chrono.hpp>
-#include <boost/system/error_code.hpp>
-
-namespace boost
-{
- namespace chrono
- {
-
-//--------------------------------------------------------------------------------------//
-// 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.
-//~ When the freeze function is called while the watch is running, the elapsed time is frozen,
-//~ allowing the elapsed time to that point to be read using the frozen function,
-//~ but the watch mechanism continues running to record total elapsed time.
-//--------------------------------------------------------------------------------------//
-
- struct dont_start_t{};
- static const dont_start_t dont_start = {};
- template <class Clock=high_resolution_clock>
- class stopwatch
- {
- public:
- typedef Clock clock;
- typedef typename Clock::duration duration;
- typedef typename Clock::time_point time_point;
-
- explicit stopwatch( system::error_code & ec = system::throws )
- : running_(false), frozen_(0), start_(0), level_(0)
- {
- start(ec);
- }
-
- explicit stopwatch( const dont_start_t& t )
- : running_(false), frozen_(0), start_(0), level_(0)
- { }
-
- time_point start( system::error_code & ec = system::throws ) {
- ++level_;
- if (!running_) {
- time_point tmp = clock::now( ec );
- if (ec) return time_point(0);
- start_ = tmp;
- running_=true;
- return start_;
- } else {
- return time_point(0);
- }
- }
-
- duration stop( system::error_code & ec = system::throws ) {
- if (running_&&(--level_==0)) {
- duration tmp = elapsed(ec);
- if (ec) return duration(0);
- frozen_ = tmp;
- running_=false;
- return frozen_;
- } else {
- return duration(0);
- }
- }
-
- time_point restart( system::error_code & ec = system::throws ) {
- time_point tmp=clock::now( ec );
- if (ec) return time_point(0);
- if (running_&&(--level_==0)) {
- frozen_ = (tmp - start_);
- } else {
- running_=true;
- }
- start_=tmp;
- ++level_;
- return start_;
- }
-
- duration elapsed( system::error_code & ec = system::throws )
- {
- if (running_) {
- return clock::now( ec ) - start_;
- } else {
- return frozen_;
- }
- }
-
- void reset( system::error_code & ec = system::throws ) {
- start_ = time_point(0);
- frozen_=0;
- level_=0;
- running_=false;
- }
- duration accumulated( ) { return 0; }
-
- private:
- bool running_;
- duration frozen_;
- time_point start_;
- std::size_t level_;
- };
-
-//--------------------------------------------------------------------------------------//
- template <class Clock=high_resolution_clock>
- class stopwatch_accumulator
- {
- public:
- typedef Clock clock;
- typedef typename Clock::duration duration;
- typedef typename Clock::time_point time_point;
-
- explicit stopwatch_accumulator( )
- : running_(false), duration_(0), start_(0), times_(0)
- { }
-
- time_point restart( system::error_code & ec = system::throws ) {
- time_point tmp=clock::now( ec );
- if (ec) return time_point(0);
- if (running_&&(--level_==0)) {
- accumulated_ += (tmp - start_);
- } else {
- running_=true;
- }
- start_=tmp;
- ++times_;
- ++level_;
- return start_;
- }
-
- time_point start( system::error_code & ec = system::throws ) {
- ++level_;
- if (!running_) {
- time_point tmp = clock::now( ec );
- if (ec) return time_point(0);
- start_ = tmp;
- running_ = true;
- ++times_;
- return start_;
- } else {
- return duration(0);
- }
- }
-
- duration stop( system::error_code & ec = system::throws ) {
- if (running_&&(--level_==0)) {
- duration tmp = elapsed(ec);
- if (ec) return duration(0);
- accumulated_ += tmp;
- running_=false;
- return accumulated_;
- } else return duration(0);
- }
-
- duration suspend( system::error_code & ec = system::throws ) {
- if (running_) {
- ++suspend_level_;
- if (!suspended_) {
- duration tmp = elapsed(ec);
- if (ec) return duration(0);
- accumulated_ += tmp;
- suspended_=true;
- return accumulated_;
- } else {
- return duration(0);
- }
- } else {
- return duration(0);
- }
- }
- 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(0);
- start_ = tmp;
- suspended_=false;
- return start;
- } else {
- return time_point(0);
- }
- }
- duration elapsed( system::error_code & ec = system::throws )
- {
- if (running_) {
- if (suspended_)
- return accumulated_;
- else {
- time_point tmp = clock::now( ec );
- if (ec) return 0;
- return accumulated_ + tmp - start_;
- } else {
- return accumulated_;
- }
- }
-
- std::size_t times() const {
- return times_
- }
- duration average() const {
- return (times_?accumulated_/times_:0;
- }
-
- void reset( system::error_code & ec = system::throws ) {
- time_point tmp = time_point(ec);
- if (ec) return 0;
- start_ = tmp;
- times_=0;
- accumulated_=0;
- }
- duration accumulated( ) { return accumulated; }
-
- private:
- bool running_;
- bool suspended_;
- duration accumulated_;
- time_point start_;
- std::size_t level_;
- std::size_t suspend_level_;
- std::size_t times_;
- };
-
-//--------------------------------------------------------------------------------------//
- typedef boost::chrono::timer< boost::chrono::system_clock > system_timer;
-#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::timer< boost::chrono::monotonic_clock > monotonic_timer;
-#endif
- typedef boost::chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
-
-//--------------------------------------------------------------------------------------//
- template <class Stopwatch> class stropwatch_enabler {
- public:
- typedef Stopwatch stopwatch_type;
- stropwatch_enabler(stopwatch_type & a, system::error_code & ec = system::throws)
- : stopwatch_(a) {
- stopwatch_.start(ec);
- }
- ~stropwatch_enabler() {
- system::error_code & ec;
- stopwatch_.stop(ec);
- }
- duration elapsed(system::error_code & ec = system::throws)
- {
- return stopwatch_.elapsed(ec)-stopwatch_.accumulated();
- }
- private:
- stopwatch_type& stopwatch_;
- stropwatch_enabler();//= delete;
- stropwatch_enabler(const enable_timer_accumulation&); // = delete;
- stropwatch_enabler& operator=(const enable_timer_accumulation&); // = delete;
-
- };
-
-//--------------------------------------------------------------------------------------//
- template <class Stopwatch> class stropwatch_suspender {
- public:
- typedef Stopwatch stopwatch_type;
- stropwatch_suspender(stopwatch_type & a, system::error_code & ec = system::throws)
- : stopwatch_(a) {
- acc_.suspend(ec);
- }
- ~stropwatch_suspender() {
- system::error_code & ec;
- acc_.resume(ec);
- }
- private:
- stopwatch_type& stopwatch_;
- stropwatch_suspender(); // = delete;
- stropwatch_suspender(const stropwatch_suspender&); // = delete;
- stropwatch_suspender& operator=(const stropwatch_suspender&); // = delete;
- }
-
-//--------------------------------------------------------------------------------------//
- template <class Stopwatch> class stropwatch_resumer {
- public:
- typedef Stopwatch stopwatch_type;
- stropwatch_resumer(stopwatch_type & a, system::error_code & ec = system::throws)
- : stopwatch_(a) {
- acc_.resume(ec);
- }
- ~stropwatch_resumer() {
- system::error_code & ec;
- acc_.suspend(ec);
- }
- private:
- stopwatch_type& stopwatch_;
- stropwatch_resumer(); // = delete;
- stropwatch_resumer(const stropwatch_resumer&); // = delete;
- stropwatch_resumer& operator=(const stropwatch_resumer&); // = delete;
- }
-
-
- } // namespace chrono
-} // namespace boost
-
-#endif
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