|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69016 - sandbox/chrono/boost/stopwatches
From: vicente.botet_at_[hidden]
Date: 2011-02-18 19:07:19
Author: viboes
Date: 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
New Revision: 69016
URL: http://svn.boost.org/trac/boost/changeset/69016
Log:
Stopwatches
Text files modified:
sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp | 62 ++++++++++++++++++++--------------------
sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp | 11 +++---
sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp | 31 ++++++++++---------
sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp | 3 +
sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp | 24 +++++++-------
sandbox/chrono/boost/stopwatches/suspendible_clock.hpp | 20 ++++++------
sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp | 7 ++-
sandbox/chrono/boost/stopwatches/time_formatter.hpp | 11 +++---
8 files changed, 87 insertions(+), 82 deletions(-)
Modified: sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp (original)
+++ sandbox/chrono/boost/stopwatches/lightweight_stopwatch.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -101,30 +101,30 @@
//--------------------------------------------------------------------------------------//
std::pair<duration, time_point> restart( system::error_code & ec = BOOST_CHRONO_THROWS )
{
- time_point tmp=clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(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 tmp=clock::now( ec );
+ if (!BOOST_CHRONO_IS_THROWS(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 = BOOST_CHRONO_THROWS )
{
if (!running_) {
time_point tmp = clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) {
- return time_point();
- }
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) {
+ return time_point();
+ }
+ }
start_ = tmp;
++level_;
running_ = true;
@@ -140,9 +140,9 @@
{
if (running_ && (--level_==0)) {
time_point tmp=clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return duration::zero();
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return duration::zero();
+ }
partial_ += tmp - start_;
traits::set_duration(get_storage(),partial_);
partial_=duration::zero();
@@ -159,9 +159,9 @@
if (running_) {
if (!suspended_) {
time_point tmp=clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return duration::zero();
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return duration::zero();
+ }
++suspend_level_;
partial_ += tmp - start_;
suspended_=true;
@@ -181,9 +181,9 @@
{
if (suspended_&&(--suspend_level_==0)) {
time_point tmp = clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return time_point();
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return time_point();
+ }
start_ = tmp;
suspended_=false;
return start_;
@@ -200,9 +200,9 @@
return traits::get_duration(get_storage());
else {
time_point tmp = clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return duration::zero();
- }
+ }
return traits::get_duration(get_storage())+tmp - start_;
}
} else {
@@ -218,9 +218,9 @@
void reset( system::error_code & ec = BOOST_CHRONO_THROWS )
{
construction_=clock::now( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return;
- }
+ }
traits::reset(get_storage());
running_=false;
suspended_=false;
Modified: sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatch_accumulator_formatter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -20,6 +20,7 @@
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/cstdint.hpp>
+#include <boost/assert.hpp>
#include <string>
#include <iostream>
#include <boost/io/ios_state.hpp>
@@ -60,16 +61,16 @@
// 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 (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
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 (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return;
- }
+ }
//if ( d < duration_t::zero() ) return;
if ( places > 9 )
places = 9; // sanity check
@@ -117,7 +118,7 @@
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");
+ BOOST_ASSERT(0 && "basic_stopwatch_accumulator_formatter internal logic error");
}
}
}
Modified: sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatch_accumulator_time_formatter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -20,6 +20,7 @@
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/cstdint.hpp>
+#include <boost/assert.hpp>
#include <string>
#include <iostream>
#include <boost/io/ios_state.hpp>
@@ -62,8 +63,8 @@
// 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 (!BOOST_CHRONO_IS_THROWS(ec))
- ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec))
+ ec.clear();
typedef typename Stopwatch::storage_type accumulator;
typedef typename Stopwatch::duration duration_t;
accumulator& acc = stopwatch_.get_storage();
@@ -94,25 +95,25 @@
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 (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(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 (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(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 (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return;
+ }
//~ os << (accumulators::max)(acc);
break;
case 'a':
@@ -120,9 +121,9 @@
//? 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 (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return;
+ }
} else {
os << 0;
}
@@ -145,7 +146,7 @@
os << accumulators::sum(acc)*100 << "/" << lt.count();
break;
default:
- assert(0 && "basic_stopwatch_accumulator_time_formatter internal logic error");
+ BOOST_ASSERT(0 && "basic_stopwatch_accumulator_time_formatter internal logic error");
}
}
}
Modified: sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatch_formatter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -18,6 +18,7 @@
#include <boost/io/ios_state.hpp>
#include <cstring>
#include <cassert>
+#include <boost/assert.hpp>
#define BOOST_STOPWATCHES_STOPWATCH_FORMAT_DEFAULT "%ds\n"
@@ -78,7 +79,7 @@
os << boost::chrono::duration<double>(d).count();
break;
default:
- assert(0 && "run_timer internal logic error");
+ BOOST_ASSERT(0 && "run_timer internal logic error");
}
}
}
Modified: sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/stopwatch_reporter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -91,55 +91,55 @@
explicit basic_stopwatch_reporter( ostream_type & os,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(Formatter::default_places()), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
explicit basic_stopwatch_reporter( const string_type & format,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(Formatter::default_places()), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
explicit basic_stopwatch_reporter( int places,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(Formatter::default_os()), m_format(Formatter::default_format()), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( ostream_type & os, const string_type & format,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(Formatter::default_places()), m_os(os), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( const string_type & format, int places,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( ostream_type & os, int places,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(os), m_format(Formatter::default_format()), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( int places, const string_type & format,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(Formatter::default_os()), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( ostream_type & os, const string_type & format, int places,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(os), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
basic_stopwatch_reporter( ostream_type & os, int places, const string_type & format,
system::error_code & ec = BOOST_CHRONO_THROWS )
: m_places(places), m_os(os), m_format(format), m_reported(false) {
- if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
}
~basic_stopwatch_reporter() {// never throws
@@ -175,9 +175,9 @@
template <class Stopwatch, class Formatter>
void basic_stopwatch_reporter<Stopwatch, Formatter>::report( system::error_code & ec ) {
stopwatches::clock_suspender<typename Stopwatch::clock> _(ec);
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return;
+ }
if ( m_format.empty() ) m_format = Formatter::default_format();
m_reported = true;
Modified: sandbox/chrono/boost/stopwatches/suspendible_clock.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/suspendible_clock.hpp (original)
+++ sandbox/chrono/boost/stopwatches/suspendible_clock.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -45,9 +45,9 @@
} else {
time_point tmp;
tmp+=duration(Clock::now(ec).time_since_epoch());
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return duration::zero();
- }
+ }
return suspended_duration_ + tmp - suspended_time_;
}
}
@@ -56,9 +56,9 @@
if (!suspended_) {
time_point tmp;
tmp+=duration(Clock::now(ec).time_since_epoch());
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return;
- }
+ }
++suspend_level_;
suspended_time_ = tmp;
suspended_=true;
@@ -71,9 +71,9 @@
if (suspended_&&(--suspend_level_==0)) {
time_point tmp;
tmp+=duration(Clock::now(ec).time_since_epoch());
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return;
- }
+ }
suspended_duration_ += tmp - suspended_time_;
suspended_=false;
} else {
@@ -126,13 +126,13 @@
static time_point now( system::error_code & ec ) {
time_point res;
typename Clock::time_point t=Clock::now(ec);
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return time_point();
- }
+ }
res+= duration(t.time_since_epoch())-suspended(ec);
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return time_point();
- }
+ }
return res;
}
Modified: sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/t24_hours_formatter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -19,6 +19,7 @@
#include <boost/io/ios_state.hpp>
#include <cstring>
#include <cassert>
+#include <boost/assert.hpp>
#define BOOST_STOPWATCHES_24_HOURS_FORMAT_DEFAULT "%d day(s) %h:%m:%s.%n\n"
@@ -60,9 +61,9 @@
{
typedef typename Stopwatch::duration duration_t;
duration_t d = stopwatch_.elapsed( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
if (ec) return;
- }
+ }
if ( d < duration_t::zero() ) return;
boost::io::ios_flags_saver ifs( os );
@@ -109,7 +110,7 @@
break;
}
default:
- assert(0 && "basic_24_hours_formatter internal logic error");
+ BOOST_ASSERT(0 && "basic_24_hours_formatter internal logic error");
}
}
}
Modified: sandbox/chrono/boost/stopwatches/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/stopwatches/time_formatter.hpp (original)
+++ sandbox/chrono/boost/stopwatches/time_formatter.hpp 2011-02-18 19:07:16 EST (Fri, 18 Feb 2011)
@@ -19,6 +19,7 @@
#include <boost/io/ios_state.hpp>
#include <cstring>
#include <cassert>
+#include <boost/assert.hpp>
#define BOOST_STOPWATCHES_TIME_FORMAT_DEFAULT "real %rs, cpu %cs (%p%), user %us, system %ss\n"
@@ -59,7 +60,7 @@
// 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 (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
+ if (!BOOST_CHRONO_IS_THROWS(ec)) ec.clear();
typedef typename Stopwatch::duration duration;
typedef typename duration::rep rep;
if ( times.real < 0 ) return;
@@ -108,7 +109,7 @@
}
break;
default:
- assert(0 && "basic_time_formatter internal logic error");
+ BOOST_ASSERT(0 && "basic_time_formatter internal logic error");
}
}
}
@@ -124,9 +125,9 @@
typedef typename Stopwatch::duration duration;
typedef typename duration::rep rep;
duration d = stopwatch_.elapsed( ec );
- if (!BOOST_CHRONO_IS_THROWS(ec)) {
- if (ec) return;
- }
+ if (!BOOST_CHRONO_IS_THROWS(ec)) {
+ if (ec) return;
+ }
rep times=d.count();
show_time<Stopwatch>(times, format, places, os, ec);
}
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