Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65201 - in sandbox/chrono/libs/stopwatches: example perf test
From: vicente.botet_at_[hidden]
Date: 2010-09-02 17:02:43


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

Log:
Added stopwatches files

Added:
   sandbox/chrono/libs/stopwatches/example/loop_stopclock_accumulator_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/nested_stopclock_accumulator_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/scoped_stopclock_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/scoped_stopwatch_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/sleep_for.hpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/specific_stopwatch_accumulator_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/stopclock_accumulator_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/stopclock_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/stopwatch_accumulator_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/stopwatch_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/t24_hours_example.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/example/timex.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/perf/stopclock_perf.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/test/Jamfile.v2 (contents, props changed)
   sandbox/chrono/libs/stopwatches/test/stopclock_constructor_overload_test.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/test/test_minmax.cpp (contents, props changed)
   sandbox/chrono/libs/stopwatches/test/wstopclock_constructor_overload_test.cpp (contents, props changed)

Added: sandbox/chrono/libs/stopwatches/example/loop_stopclock_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/loop_stopclock_accumulator_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,42 @@
+// stopwatch_accumulator_example.cpp ---------------------------------------------------//
+
+// Copyright 2009 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/chrono for documentation.
+
+//#include <boost/chrono/stopclock_accumulator.hpp>
+#include <boost/stopwatches/stopwatches.hpp>
+
+#include <cmath>
+#include "sleep_for.hpp"
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+int f1(long j)
+{
+ stopclock_accumulator<> acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ for ( long i = 0; i < j; ++i ) {
+ stopclock_accumulator<>::scoped_run _(acc);
+ //~ std::cout << "i="<<i <<" ";
+ //~ std::cout << " j="<<j <<" ";
+ //~ stopclock<> s;
+ std::sqrt( 123.456L ); // burn some time
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(20));
+ }
+
+
+ return 0;
+}
+int main()
+{
+ static stopclock_accumulator<> acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ stopclock_accumulator<>::scoped_run _(acc);
+
+ f1(100);
+ f1(200);
+ f1(300);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/nested_stopclock_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/nested_stopclock_accumulator_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,71 @@
+// stopwatch_accumulator_example.cpp ---------------------------------------------------//
+
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/stopwatches.hpp>
+#include <cmath>
+//#include <boost/thread.hpp>
+#include "sleep_for.hpp"
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+
+#define BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR \
+ static stopclock_accumulator<> BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__)( \
+ std::string(__FILE__) + "[" + BOOST_STRINGIZE(__LINE__) + "] " + stopwatch_accumulator_formatter::default_format() \
+ ); \
+ stopclock_accumulator<>::scoped_run BOOST_JOIN(_boost_chrono_stopclock_accumulator_run_, __LINE__)(BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__))
+
+#define BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_FCT \
+ static stopclock_accumulator<> BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__)( \
+ std::string(BOOST_CURRENT_FUNCTION) + ": " + stopwatch_accumulator_formatter::default_format() \
+ ); \
+ stopclock_accumulator<>::scoped_run BOOST_JOIN(_boost_chrono_stopclock_accumulator_run_, __LINE__)(BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__))
+
+#define BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_FCT_REVERSE \
+ static stopclock_accumulator<> BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__)( \
+ std::string(BOOST_CURRENT_FUNCTION) + "(between calls): " + stopwatch_accumulator_formatter::default_format() \
+ ); \
+ stopclock_accumulator<>::scoped_stop BOOST_JOIN(_boost_chrono_stopclock_accumulator_stop_, __LINE__)(BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__))
+
+void f1()
+{
+ //~ static stopclock_accumulator<> acc(
+ //~ std::string(__FILE__) + "[" + BOOST_STRINGIZE(__LINE__) + "] " + stopwatch_accumulator_formatter::default_format()
+ //~ );
+ //~ stopclock_accumulator<>::scoped_run _(acc);
+ BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_FCT;
+ //BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_FCT_REVERSE;
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
+ {
+ BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR;
+ //~ static stopclock_accumulator<> acc(
+ //~ std::string(__FILE__) + "[" + BOOST_STRINGIZE(__LINE__) + "] " + stopwatch_accumulator_formatter::default_format()
+ //~ );
+ //~ stopclock_accumulator<>::scoped_run _(acc);
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
+ }
+
+}
+int main()
+{
+ BOOST_STOPWATCHES_STOPCLOCK_ACCUMULATOR_FCT;
+ //~ static stopclock_accumulator<> acc(
+ //~ std::string(__FILE__) + "[" + BOOST_STRINGIZE(__LINE__) + "] " + stopwatch_accumulator_formatter::default_format()
+ //~ );
+ //~ stopclock_accumulator<>::scoped_run _(acc);
+
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
+ f1();
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
+ f1();
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
+ f1();
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(200));
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/scoped_stopclock_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/scoped_stopclock_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,32 @@
+// stopclock_example.cpp ---------------------------------------------------//
+
+// 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatches.hpp>
+#include <cmath>
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+int f1(long j)
+{
+ scoped_stopclock<> _(BOOST_CURRENT_FUNCTION);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+ scoped_stopclock<> _(BOOST_CURRENT_FUNCTION);
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/scoped_stopwatch_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/scoped_stopwatch_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,37 @@
+// stopwatch_example.cpp ---------------------------------------------------//
+
+// 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatches.hpp>
+#include <cmath>
+#include "sleep_for.hpp"
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+long double res;
+void f1(long j)
+{
+ stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ for (long i =0; i< j; i+=1)
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (j!=0) f1(j-1);
+ stopwatch_reporter<stopwatch<> >::scoped_suspend s(_);
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
+
+}
+int main()
+{
+ stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+
+ res=0;
+ for (long i =0; i< 3; ++i)
+ f1(i*100);
+
+ std::cout<< res << std::endl;
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/sleep_for.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/sleep_for.hpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,19 @@
+#ifndef BOOST_CHRONO_SLEEP_FOR__HPP
+#define BOOST_CHRONO_SLEEP_FOR__HPP
+
+#include <boost/chrono/chrono.hpp>
+
+namespace boost {
+namespace this_thread {
+
+
+template <class Rep, class Period>
+void sleep_for(const boost::chrono::duration<Rep, Period>& d)
+{
+ boost::chrono::high_resolution_clock::time_point go = boost::chrono::high_resolution_clock::now() + d;
+ while (boost::chrono::high_resolution_clock::now() < go);
+}
+}
+}
+
+#endif //BOOST_CHRONO_SLEEP_FOR__HPP

Added: sandbox/chrono/libs/stopwatches/example/specific_stopwatch_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/specific_stopwatch_accumulator_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,101 @@
+// stopwatch_accumulator_example.cpp ---------------------------------------------------//
+
+// 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatches.hpp>
+#include <cmath>
+#include <boost/accumulators/statistics/variance.hpp>
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+using namespace boost::accumulators;
+
+ class my_stopwatch_accumulator_formatter {
+ public:
+ typedef std::string string_type;
+ typedef char char_type;
+ typedef std::ostream ostream_type;
+
+ static ostream_type & default_os() {return std::cout;}
+ static const char_type* default_format() {return "%c times, sum=%ss, mean=%as, variance=%vs\n";}
+ static int default_places() { return 3; }
+
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char_type* format,
+ int places, ostream_type & os, boost::system::error_code & ec)
+ {
+ if (&ec != &boost::system::throws) ec.clear();
+ typedef typename Stopwatch::storage_type accumulator_t;
+ typedef typename Stopwatch::duration duration_t;
+ accumulator_t& acc = stopwatch_.get_storage();
+
+ 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("acsv", *(format+1)) ) {
+ os << *format;
+ } else {
+ ++format;
+ switch ( *format ) {
+ case 's':
+ os << boost::chrono::duration<double>(duration_t(sum(acc))).count();
+ break;
+ case 'a':
+ os << count(acc)>0?boost::chrono::duration<double>(duration_t(typename duration_t::rep(sum(acc)))).count()/count(acc):0;
+ break;
+ case 'c':
+ os << count(acc);
+ break;
+ case 'v':
+ os << boost::chrono::duration<double>(duration_t(typename duration_t::rep(variance(acc)))).count();
+ break;
+ default:
+ assert(0 && "my_stopwatch_accumulator_formatter internal logic error");
+ }
+ }
+ }
+ }
+ };
+
+
+typedef stopwatch_reporter<
+ stopwatch_accumulator<process_real_cpu_clock,
+ features<
+ tag::count,
+ tag::sum,
+ tag::mean,
+ tag::variance(lazy)
+ >
+ >
+ , my_stopwatch_accumulator_formatter
+ > my_stopwatch_accumulator_reporter;
+
+int f1(long j)
+{
+ //static my_stopwatch_accumulator_reporter acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ static my_stopwatch_accumulator_reporter acc;
+ my_stopwatch_accumulator_reporter::scoped_run _(acc);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+ static my_stopwatch_accumulator_reporter acc;
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}
+

Added: sandbox/chrono/libs/stopwatches/example/stopclock_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/stopclock_accumulator_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,39 @@
+// stopwatch_accumulator_example.cpp ---------------------------------------------------//
+
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/stopwatches/stopclock_accumulator.hpp>
+
+#include <cmath>
+#include "sleep_for.hpp"
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+template <typename Clock>
+int f1(long j)
+{
+ static stopclock_accumulator<Clock> acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ typename stopclock_accumulator<Clock>::scoped_run _(acc);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(20));
+
+
+ return 0;
+}
+int main()
+{
+ static stopclock_accumulator<process_cpu_clock> acc(BOOST_STOPWATCHES_ACCUMULATOR_TIME_FUNCTION_FORMAT);
+ stopclock_accumulator<process_cpu_clock>::scoped_run _(acc);
+
+ f1<high_resolution_clock>(1000);
+ f1<high_resolution_clock>(2000);
+ f1<high_resolution_clock>(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/stopclock_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/stopclock_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,33 @@
+// stopclock_example.cpp ---------------------------------------------------//
+
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/stopwatches/stopclock.hpp>
+#include <cmath>
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+
+int f1(long j)
+{
+ stopclock<> _(BOOST_STOPWATCHES_TIME_FUNCTION_FORMAT);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+ stopclock<> _(BOOST_STOPWATCHES_TIME_FUNCTION_FORMAT);
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/stopwatch_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/stopwatch_accumulator_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,33 @@
+// stopwatch_accumulator_example.cpp ---------------------------------------------------//
+
+// 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatches.hpp>
+#include <cmath>
+
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+int f1(long j)
+{
+ static stopwatch_reporter<stopwatch_accumulator<process_real_cpu_clock> > acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ stopwatch_reporter<stopwatch_accumulator<process_real_cpu_clock> >::scoped_run _(acc);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/stopwatch_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/stopwatch_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,33 @@
+// stopwatch_example.cpp ---------------------------------------------------//
+
+// Copyright Beman Dawes 2006, 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatches.hpp>
+#include <cmath>
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+int f1(long j)
+{
+ stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+ stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/t24_hours_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/t24_hours_example.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,37 @@
+// t24_hours_example.cpp ---------------------------------------------------//
+
+// Copyright Beman Dawes 2006, 2008
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/stopwatches/stopwatch.hpp>
+#include <boost/stopwatches/stopwatch_reporter.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/stopwatches/t24_hours_formatter.hpp>
+#include <cmath>
+
+using namespace boost::chrono;
+using namespace boost::stopwatches;
+int f1(long j)
+{
+ stopwatch_reporter<stopwatch<process_real_cpu_clock>, t24_hours_formatter> hhmmss(BOOST_STOPWATCHES_24_HOURS_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch<process_real_cpu_clock>, t24_hours_formatter> hhmmss;
+
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
+
+ return 0;
+}
+int main()
+{
+ stopwatch_reporter<stopwatch<process_real_cpu_clock>, t24_hours_formatter> hhmmss(BOOST_STOPWATCHES_24_HOURS_FUNCTION_FORMAT);
+
+ f1(1000);
+ f1(2000);
+ f1(3000);
+ return 0;
+}

Added: sandbox/chrono/libs/stopwatches/example/timex.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/example/timex.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,47 @@
+// timex: timed execution program ------------------------------------------//
+
+// Copyright Beman Dawes 2007
+
+// 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.
+
+#include <boost/stopwatches/stopclock.hpp>
+#include <cstdlib>
+#include <string>
+#include <iostream>
+
+int main( int argc, char * argv[] )
+{
+ if ( argc == 1 )
+ {
+ std::cout << "invoke: timex [-v] command [args...]\n"
+ " command will be executed and timings displayed\n"
+ " -v option causes command and args to be displayed\n";
+ return 1;
+ }
+
+ std::string s;
+
+ bool verbose = false;
+ if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
+ {
+ verbose = true;
+ ++argv;
+ --argc;
+ }
+
+ for ( int i = 1; i < argc; ++i )
+ {
+ if ( i > 1 ) s += ' ';
+ s += argv[i];
+ }
+
+ if ( verbose )
+ { std::cout << "command: \"" << s.c_str() << "\"\n"; }
+
+ boost::stopwatches::stopclock<> t;
+
+ return std::system( s.c_str() );
+}

Added: sandbox/chrono/libs/stopwatches/perf/stopclock_perf.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/perf/stopclock_perf.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,796 @@
+// stopclock_perf.cpp ---------------------------------------------------//
+
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/thread.hpp>
+#include <boost/chrono/stopclock.hpp>
+#include <boost/chrono/thread_clock.hpp>
+
+#include <boost/chrono/suspendible_clock.hpp>
+#include <boost/chrono/stopclock_accumulator.hpp>
+#include <cmath>
+
+using namespace boost::chrono;
+double res;
+
+
+namespace rep_none {
+ std::size_t count[11];
+
+ template <typename Clock>
+ void f10(long v);
+
+ template <typename Clock>
+ void f1(long v) {
+ std::cout<< ">>> f1 " << v << "\n";
+ ++count[1];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+ f10<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f2(long v) {
+ std::cout<< ">>> f2 " << v << "\n";
+ ++count[2];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=2) return;
+
+ f1<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f3(long v) {
+ std::cout<< ">>> f3 " << v << "\n";
+ ++count[3];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=3) return;
+
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f4(long v) {
+ std::cout<< ">>> f4 " << v << "\n";
+ ++count[4];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=4) return;
+
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f5(long v) {
+ std::cout<< ">>> f5 " << v << "\n";
+ ++count[5];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=5) return;
+
+ if (v%4==0) {f4<Clock>(v-1); return;}
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f6(long v) {
+ std::cout<< ">>> f6 " << v << "\n";
+ ++count[6];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=6) return;
+
+ if (v%5==0) {f5<Clock>(v-1); return;}
+ if (v%4==0) {f4<Clock>(v-1); return;}
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f7(long v) {
+ std::cout<< ">>> f7 " << v << "\n";
+ ++count[7];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=7) return;
+
+ if (v%6==0) {f6<Clock>(v-1); return;}
+ if (v%5==0) {f5<Clock>(v-1); return;}
+ if (v%4==0) {f4<Clock>(v-1); return;}
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f8(long v) {
+ std::cout<< ">>> f8 " << v << "\n";
+ ++count[8];
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=8) return;
+
+ if (v%7==0) {f7<Clock>(v-1); return;}
+ if (v%6==0) {f6<Clock>(v-1); return;}
+ if (v%5==0) {f5<Clock>(v-1); return;}
+ if (v%4==0) {f4<Clock>(v-1); return;}
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f9(long v) {
+ std::cout<< ">>> f9 " << v << "\n";
+ ++count[9];
+ //std::cout<< ">>> COUNT NONE " << " " << rep_none::count[9] << std::endl;
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=9) return;
+
+ if (v%8==0) {f8<Clock>(v-1); return;}
+ if (v%7==0) {f7<Clock>(v-1); return;}
+ if (v%6==0) {f6<Clock>(v-1); return;}
+ if (v%5==0) {f5<Clock>(v-1); return;}
+ if (v%4==0) {f4<Clock>(v-1); return;}
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f10(long v) {
+ std::cout<< ">>> f10 " << v << "\n";
+ ++count[10];
+ //std::cout<< ">>> COUNT NONE 10 " << " " << rep_none::count[10] << std::endl;
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+
+ if ((v%9)==0) {f9<Clock>(v-1); return;}
+ if ((v%8)==0) {f8<Clock>(v-1); return;}
+ if ((v%7)==0) {f7<Clock>(v-1); return;}
+ if ((v%6)==0) {f6<Clock>(v-1); return;}
+ if ((v%5)==0) {f5<Clock>(v-1); return;}
+ if ((v%4)==0) {f4<Clock>(v-1); return;}
+ if ((v%3)==0) {f3<Clock>(v-1); return;}
+ if ((v%2)==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f(long j)
+ {
+ ++count[0];
+ for ( long i = 0; i < j; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (j>1) {
+ f<Clock>(j-1);
+ }
+ //boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+}
+
+
+namespace rep_basic {
+ std::size_t count[11];
+
+ template <typename Clock>
+ void f10(long v);
+
+ template <typename Clock>
+ void f1(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+ f10<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f2(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=2) return;
+
+ f1<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f3(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=3) return;
+
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f4(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=4) return;
+
+ if (v%3==0) {f3<Clock>(v-1); return;}
+ if (v%2==0) {f2<Clock>(v-1); return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f5(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=5) return;
+
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f6(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=6) return;
+
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f7(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=7) return;
+
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f8(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=8) return;
+
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f9(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=9) return;
+
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f10(long v) {
+ stopclock<Clock> b(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+
+ if (v%9==0) {f9<Clock>(v-1);return;}
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f(long j)
+ {
+ stopclock<Clock> b(9);
+
+ for ( long i = 0; i < j; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (j>1) {
+ //std::cout << "f1("<<j-1<<")\n";
+ f<Clock>(j-1);
+ }
+ //boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+}
+
+namespace rep_suspendible {
+ std::size_t count[11];
+
+ template <typename Clock>
+ void f10(long v);
+
+ template <typename Clock>
+ void f1(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=1) return;
+ f10<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f2(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=2) return;
+
+ f1<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f3(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=3) return;
+
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f4(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=4) return;
+
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f5(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=5) return;
+
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f6(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=6) return;
+
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f7(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=7) return;
+
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f8(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=8) return;
+
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f9(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=9) return;
+
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f10(long v) {
+ stopclock<suspendible_clock<Clock> > a(9);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+
+ if (v%9==0) {f9<Clock>(v-1);return;}
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f(long j)
+ {
+ stopclock<suspendible_clock<Clock> > a(9);
+
+ for ( long i = 0; i < j; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (j>1) {
+ //std::cout << "f1("<<j-1<<")\n";
+ f<Clock>(j-1);
+ }
+ //boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+}
+
+namespace rep_accu {
+ std::size_t count[11];
+
+ template <typename Clock>
+ void f10(long v);
+
+ template <typename Clock>
+ void f1(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+ f10<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f2(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=2) return;
+
+ f1<Clock>(v-1);
+ }
+
+ template <typename Clock>
+ void f3(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=3) return;
+
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f4(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=4) return;
+
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f5(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=5) return;
+
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f6(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=6) return;
+
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f7(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=7) return;
+
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f8(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=8) return;
+
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f9(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=9) return;
+
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f10(long v) {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+ // burn some time
+ for ( long i = 0; i < v; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (v<=10) return;
+
+ if (v%9==0) {f9<Clock>(v-1);return;}
+ if (v%8==0) {f8<Clock>(v-1);return;}
+ if (v%7==0) {f7<Clock>(v-1);return;}
+ if (v%6==0) {f6<Clock>(v-1);return;}
+ if (v%5==0) {f5<Clock>(v-1);return;}
+ if (v%4==0) {f4<Clock>(v-1);return;}
+ if (v%3==0) {f3<Clock>(v-1);return;}
+ if (v%2==0) {f2<Clock>(v-1);return;}
+ f1<Clock>(v-1);
+ }
+ template <typename Clock>
+ void f(long j)
+ {
+ static stopclock_accumulator<Clock> acc(9);
+ typename stopclock_accumulator<Clock>::scoped_run c(acc);
+
+ for ( long i = 0; i < j; ++i )
+ res+=std::sqrt( res+123.456L+i ); // burn some time
+ if (j>1) {
+ //std::cout << "f1("<<j-1<<")\n";
+ f<Clock>(j-1);
+ }
+ //boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
+}
+
+template <typename Clock, long SIZE>
+void test_clock_size()
+{
+ long K =1;
+ std::cout << ">>> test_clock_size " << SIZE << std::endl;
+ {
+ rep_none::count[0]=0;
+ res=0;
+ stopclock<Clock> b(9, std::string(">>> REC NONE ")+ stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_none::f<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ std::cout<< ">>> COUNT REC NONE " << SIZE << " " << rep_none::count[0] << std::endl;
+
+ }
+ {
+ res=0;
+ stopclock<Clock> b(9, std::string(">>> REC BASIC ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_basic::f<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+ {
+ res=0;
+ stopclock<suspendible_clock<Clock> > a(9, std::string(">>> REC SUSPEND ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_suspendible::f<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+ {
+ res=0;
+ stopclock<Clock> b(9, std::string(">>> REC ACCU ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_accu::f<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+ {
+ res=0;
+ for (int i=1;i<=10;i++) rep_none::count[i]=0;
+ stopclock<Clock> b(9, std::string(">>> NON_REC NONE ")+ stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_none::f10<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ std::size_t c=0;
+ for (int i=1;i<=10;i++)
+ c+= rep_none::count[i];
+ std::cout<< ">>> COUNT NON_REC NONE " << SIZE << " " << c << std::endl;
+ }
+ {
+ res=0;
+ stopclock<Clock> b(9, std::string(">>> NON_REC BASIC ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_basic::f10<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+ {
+ res=0;
+ stopclock<suspendible_clock<Clock> > a(9, std::string(">>> NON_REC SUSPEND ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_suspendible::f10<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+ {
+ res=0;
+ stopclock<Clock> b(9, std::string(">>> NON_REC ACCU ") + stopwatch_formatter::default_format());
+
+ for (long i =1; i<= K; ++i)
+ rep_accu::f10<Clock>(i*SIZE);
+ std::cout<< res << std::endl;
+ }
+#if 0
+#endif
+}
+
+template <typename Clock>
+void test_clock()
+{
+ //test_clock_size<Clock, 3200>();
+ //test_clock_size<Clock, 1600>();
+ //test_clock_size<Clock, 800>();
+ //test_clock_size<Clock, 400>();
+ //test_clock_size<Clock, 200>();
+ test_clock_size<Clock, 1050>();
+ test_clock_size<Clock, 1040>();
+ test_clock_size<Clock, 1030>();
+ test_clock_size<Clock, 1020>();
+ test_clock_size<Clock, 1010>();
+ test_clock_size<Clock, 1000>();
+ test_clock_size<Clock, 100>();
+
+
+
+
+
+
+}
+
+
+int main() {
+#ifdef BOOST_CHRONO_HAS_THREAD_CLOCK
+ std::cout << ">>> main thread_clock" << std::endl;
+ test_clock<thread_clock>();
+#endif
+ std::cout << ">>> main high_resolution_clock" << std::endl;
+ test_clock<high_resolution_clock>();
+#ifdef BOOST_CHRONO_HAS_THREAD_CLOCK
+ std::cout << ">>> main thread_clock" << std::endl;
+ test_clock<thread_clock>();
+#endif
+
+ return 0;
+
+}

Added: sandbox/chrono/libs/stopwatches/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/test/Jamfile.v2 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,76 @@
+# Boost Chrono Library test Jamfile
+
+# Copyright Beman Dawes 2003, 2006, 2008
+
+# Distributed under the Boost Software License, Version 1.0.
+# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt
+
+# See library home page at http://www.boost.org/libs/chrono
+
+# uncomment one if the above lines if you build outside the Boost release
+#local BOOST_ROOT = /boost_1_41_0 ;
+#local BOOST_ROOT = c:/cygwin/boost_1_41_0 ;
+
+if ! $(BOOST_ROOT)
+{
+ BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
+}
+
+project
+ : requirements
+ <os>LINUX:<threading>multi
+ <library>/boost/chrono//boost_chrono
+ <library>/boost/system//boost_system
+ #<library>/boost/thread//boost_thread/<link>shared
+ # uncomment the line above if you build outside the Boost release
+ #<include>$(BOOST_ROOT)
+ # uncomment the line above if you build outside the Boost release
+ #<include>../../..
+ <toolset>msvc:<asynch-exceptions>on
+ <define>BOOST_ENABLE_WARNINGS
+ <warnings>all
+ <toolset>gcc:<cxxflags>-Wextra
+ <toolset>gcc:<cxxflags>-Wno-long-long
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-Wno-missing-field-initializers
+ <toolset>gcc-mingw-4.5.0:<cxxflags>-fdiagnostics-show-option
+ <toolset>msvc:<cxxflags>/wd4127
+ ;
+
+
+
+ test-suite "stopwatch"
+ :
+ [ run ../example/stopwatch_example.cpp : : : <link>static ]
+ [ run ../example/stopwatch_example.cpp : : : : stopwatch_example_dll ]
+ [ run ../example/scoped_stopwatch_example.cpp : : : <link>static ]
+ [ run ../example/scoped_stopwatch_example.cpp : : : : scoped_stopwatch_example_dll ]
+ [ run ../example/stopwatch_accumulator_example.cpp : : : <link>static ]
+ [ run ../example/stopwatch_accumulator_example.cpp : : : : stopwatch_accumulator_example_dll ]
+ [ run ../example/specific_stopwatch_accumulator_example.cpp : : : <link>static ]
+ [ run ../example/specific_stopwatch_accumulator_example.cpp : : : : specific_stopwatch_accumulator_example_dll ]
+ [ run ../example/stopclock_example.cpp : : : <link>static ]
+ [ run ../example/stopclock_example.cpp : : : : stopclock_example_dll ]
+ [ run ../example/stopclock_accumulator_example.cpp : : : <link>static ]
+ [ run ../example/stopclock_accumulator_example.cpp : : : : stopclock_accumulator_example_dll ]
+ [ run ../example/nested_stopclock_accumulator_example.cpp : : : <link>static ]
+ [ run ../example/nested_stopclock_accumulator_example.cpp : : : : nested_stopclock_accumulator_example_dll ]
+ [ run ../example/loop_stopclock_accumulator_example.cpp : : : <link>static ]
+ [ run ../example/loop_stopclock_accumulator_example.cpp : : : : loop_stopclock_accumulator_example_dll ]
+ [ run ../example/t24_hours_example.cpp : : : <link>static ]
+ [ run ../example/t24_hours_example.cpp : : : : t24_hours_example_dll ]
+ [ run ../example/scoped_stopclock_example.cpp : : : <link>static ]
+ [ run ../example/scoped_stopclock_example.cpp : : : : function_stopclock_example_dll ]
+ [ link ../example/timex.cpp : <link>static ]
+ [ link ../example/timex.cpp : : timex_dll ]
+ [ compile test_minmax.cpp ]
+ [ run stopclock_constructor_overload_test.cpp : : : <link>static ]
+ [ run stopclock_constructor_overload_test.cpp : : : : stopclock_constructor_overload_test_dll ]
+ [ run wstopclock_constructor_overload_test.cpp : : : <link>static ]
+ [ run wstopclock_constructor_overload_test.cpp : : : : wstopclock_constructor_overload_test_dll ]
+ ;
+
+ test-suite "perf"
+ :
+ #[ run ../perf/stopclock_perf.cpp : : : <library>/boost/thread//boost_thread <link>static ]
+ #[ run ../perf/stopclock_perf.cpp : : : <library>/boost/thread//boost_thread : stopclock_perf_dll ]
+ ;

Added: sandbox/chrono/libs/stopwatches/test/stopclock_constructor_overload_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/test/stopclock_constructor_overload_test.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,76 @@
+// boost stopclock_constructor_overload_test.cpp -----------------------------------------------------//
+
+// Copyright Beman Dawes 2006, 2008
+// Copyright 2009 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/chrono for documentation.
+
+#include <boost/stopwatches/stopclock.hpp>
+#include <cstdlib> // for atol()
+#include <iostream>
+#include <sstream>
+#include <locale>
+#include <ctime>
+#include <cmath> // for sqrt(), used to burn time
+
+using boost::stopwatches::stopclock;
+using boost::stopwatches::time_formatter;
+using boost::system::error_code;
+
+#include <boost/test/minimal.hpp>
+
+namespace
+{
+
+ void stopclock_constructor_overload_test()
+ {
+ // exercise each supported combination of constructor arguments
+
+ std::ostream & os = std::cout;
+ const int pl = 9;
+ boost::system::error_code ec;
+
+ stopclock<> t1;
+ stopclock<> t2( os );
+ stopclock<> t3( ec );
+ stopclock<> t4( os, ec );
+ stopclock<> t5( pl );
+ stopclock<> t6( os, pl );
+ stopclock<> t7( pl, ec );
+ stopclock<> t8( os, pl, ec );
+ stopclock<> t9( "t9, default places, r %r, c %c, p %p, u %u, s %s\n" );
+ stopclock<> t10( os, "t10, default places, r %r, c %c, p %p, u %u, s %s\n" );
+ stopclock<> t11( "t11, default places, r %r, c %c, p %p, u %u, s %s\n", ec );
+ stopclock<> t12( os, "t12, default places, r %r, c %c, p %p, u %u, s %s\n", ec );
+ stopclock<> t13( pl, "t13, explicitly code places, r %r, c %c, p %p, u %u, s %s\n" );
+ stopclock<> t14( "t14, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl );
+ stopclock<> t15( os, pl, "t15, explicitly code places, r %r, c %c, p %p, u %u, s %s\n" );
+ stopclock<> t16( os, "t16, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl );
+ stopclock<> t17( pl, "t17, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", ec );
+ stopclock<> t18( "t18, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl, ec );
+ stopclock<> t19( os, pl, "t19, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", ec );
+ stopclock<> t20( os, "t20, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl, ec );
+
+ std::cout << "Burn some time so run_timers have something to report...";
+ boost::stopwatches::stopwatch<boost::chrono::high_resolution_clock> t;
+ while ( t.elapsed() < boost::chrono::seconds(1) ) {}
+ std::cout << "\n";
+ std::cout << time_formatter::default_places() << " default places\n";
+ std::cout << pl << " explicitly coded places\n";
+ }
+
+}
+
+int test_main( int /*argc*/, char * /*argv*/[] )
+{
+ std::locale loc( "" ); // test with appropriate locale
+ std::cout.imbue( loc );
+
+ stopclock_constructor_overload_test();
+
+ return 0;
+}
+

Added: sandbox/chrono/libs/stopwatches/test/test_minmax.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/test/test_minmax.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,18 @@
+// test_duration.cpp ----------------------------------------------------------//
+
+// Copyright 2009 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#define min(A,B) ((A)<(B)?(A):(B))
+#define max(A,B) ((A)>(B)?(A):(B))
+
+#include <boost/stopwatches/stopwatches.hpp>
+
+ int main()
+ {
+ boost::stopwatches::stopclock<> _;
+ }
+

Added: sandbox/chrono/libs/stopwatches/test/wstopclock_constructor_overload_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/stopwatches/test/wstopclock_constructor_overload_test.cpp 2010-09-02 17:02:40 EDT (Thu, 02 Sep 2010)
@@ -0,0 +1,137 @@
+// boost run_timer_test.cpp -----------------------------------------------------//
+
+// Copyright Beman Dawes 2006, 2008
+// Copyright 2009 Vicente J. Botet Escriba
+// Copyright 2010 Tan Zhi(Tom)
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+// See http://www.boost.org/libs/chrono for documentation.
+
+#include <boost/stopwatches/stopclock.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
+#include <boost/stopwatches/stopwatch.hpp>
+
+#include <cstdlib> // for atol()
+#include <iostream>
+#include <sstream>
+#include <locale>
+#include <ctime>
+#include <cmath> // for sqrt(), used to burn time
+
+#include <string>
+
+using boost::stopwatches::stopwatch;
+using boost::stopwatches::stopclock;
+using boost::chrono::process_cpu_clock;
+using boost::stopwatches::wtime_formatter;
+using boost::stopwatches::time_formatter;
+using boost::system::error_code;
+using boost::stopwatches::detail::adaptive_string;
+#include <boost/test/minimal.hpp>
+
+
+namespace util
+{
+
+ /**
+ * this class return std::cout or std::wcout according to
+ * the context(e.g. type on the left side of '=' operator)
+ */
+ struct console
+ {
+
+ template <
+ typename Traits
+ >
+ operator std::basic_ostream<char,Traits>&() const
+ {
+ return std::cout;
+ }
+#ifndef BOOST_NO_STD_WSTRING
+ template <
+ typename Traits
+ >
+ operator std::basic_ostream<wchar_t,Traits>&() const
+ {
+ return std::wcout;
+ }
+#endif
+ };
+
+} // namespace util
+
+
+ // overload adaptive_string for streaming operation with cout/wcout
+ template<class charT>
+ std::basic_ostream<charT>& operator << (std::basic_ostream<charT>& os, const boost::stopwatches::detail::adaptive_string& s)
+ {
+ os << std::basic_string<charT>(s);
+ return os;
+ }
+
+
+namespace
+{
+ using namespace util;
+
+ template<class stopclock_type>
+ void stopclock_constructor_overload_test()
+ {
+ // exercise each supported combination of constructor arguments
+
+ typename stopclock_type::ostream_type& os = console();
+ const int pl = 9;
+ boost::system::error_code ec;
+
+ stopclock_type t1;
+ stopclock_type t2( os );
+ stopclock_type t3( ec );
+ stopclock_type t4( os, ec );
+ stopclock_type t5( pl );
+ stopclock_type t6( os, pl );
+ stopclock_type t7( pl, ec );
+ stopclock_type t8( os, pl, ec );
+ stopclock_type t9( adaptive_string("t9, default places, r %r, c %c, p %p, u %u, s %s\n") );
+ stopclock_type t10( os, adaptive_string("t10, default places, r %r, c %c, p %p, u %u, s %s\n") );
+ stopclock_type t11( adaptive_string("t11, default places, r %r, c %c, p %p, u %u, s %s\n"), ec );
+ stopclock_type t12( os, adaptive_string("t12, default places, r %r, c %c, p %p, u %u, s %s\n"), ec );
+ stopclock_type t13( pl, adaptive_string("t13, explicitly code places, r %r, c %c, p %p, u %u, s %s\n") );
+ stopclock_type t14( adaptive_string("t14, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), pl );
+ stopclock_type t15( os, pl, adaptive_string("t15, explicitly code places, r %r, c %c, p %p, u %u, s %s\n") );
+ stopclock_type t16( os, adaptive_string("t16, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), pl );
+ stopclock_type t17( pl, adaptive_string("t17, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), ec );
+ stopclock_type t18( adaptive_string("t18, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), pl, ec );
+ stopclock_type t19( os, pl, adaptive_string("t19, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), ec );
+ stopclock_type t20( os, adaptive_string("t20, explicitly code places, r %r, c %c, p %p, u %u, s %s\n"), pl, ec );
+
+ std::cout << adaptive_string("Burn some time so run_timers have something to report...");
+
+ boost::stopwatches::stopwatch<boost::chrono::high_resolution_clock> t;
+ while ( t.elapsed() < boost::chrono::seconds(1) ) {}
+
+ std::cout << adaptive_string("\n");
+ std::cout << time_formatter::default_places() << adaptive_string(" default places\n");
+ std::cout << pl << adaptive_string(" explicitly coded places\n");
+ }
+
+ typedef stopclock <> stopclock_t;
+ typedef stopclock <
+ process_cpu_clock,
+ boost::stopwatches::wtime_formatter
+ > wstopclock_t;
+}
+
+int test_main( int /*argc*/, char * /*argv*/[] )
+{
+ std::locale loc( "" ); // test with appropriate locale
+ std::cout.imbue( loc );
+
+ stopclock_constructor_overload_test<stopclock_t>(); // test for char
+#ifndef BOOST_NO_STD_WSTRING
+ stopclock_constructor_overload_test<wstopclock_t>(); // test for wchar_t
+#endif
+ return 0;
+}
+


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