Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59254 - in sandbox/chrono/libs/chrono: example test
From: vicente.botet_at_[hidden]
Date: 2010-01-24 12:14:39


Author: viboes
Date: 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
New Revision: 59254
URL: http://svn.boost.org/trac/boost/changeset/59254

Log:
Boost.Chrono: Version 0.3.2,
* Added specific stopwatch_accumulator_formatter with variant stat
* Added stopclock for loop example
* warning removal unused variable
Added:
   sandbox/chrono/libs/chrono/example/loop_stopclock_accumulator_example.cpp (contents, props changed)
Text files modified:
   sandbox/chrono/libs/chrono/example/nested_stopclock_accumulator_example.cpp | 2
   sandbox/chrono/libs/chrono/example/scoped_stopwatch_example.cpp | 7 ++-
   sandbox/chrono/libs/chrono/example/specific_stopwatch_accumulator_example.cpp | 68 ++++++++++++++++++++++++++++++++++++---
   sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp | 5 ++
   sandbox/chrono/libs/chrono/test/Jamfile.v2 | 6 ++-
   sandbox/chrono/libs/chrono/test/test_duration.cpp | 2 +
   6 files changed, 78 insertions(+), 12 deletions(-)

Added: sandbox/chrono/libs/chrono/example/loop_stopclock_accumulator_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/example/loop_stopclock_accumulator_example.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -0,0 +1,41 @@
+// 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/chrono/stopwatches.hpp>
+
+#include <cmath>
+#include <boost/thread.hpp>
+
+using namespace boost::chrono;
+int f1(long j)
+{
+ stopclock_accumulator<> acc(BOOST_CHRONO_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(boost::posix_time::milliseconds(20));
+ }
+
+
+ return 0;
+}
+int main()
+{
+ static stopclock_accumulator<> acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
+ stopclock_accumulator<>::scoped_run _(acc);
+
+ f1(100);
+ f1(200);
+ f1(300);
+ return 0;
+}

Modified: sandbox/chrono/libs/chrono/example/nested_stopclock_accumulator_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/nested_stopclock_accumulator_example.cpp (original)
+++ sandbox/chrono/libs/chrono/example/nested_stopclock_accumulator_example.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -23,7 +23,7 @@
     static stopclock_accumulator<> BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__)( \
         std::string(BOOST_CURRENT_FUNCTION) + ": " + stopwatch_accumulator_formatter::default_format() \
     ); \
- stopclock_accumulator<>::scoped_stop BOOST_JOIN(_boost_chrono_stopclock_accumulator_run_, __LINE__)(BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__))
+ stopclock_accumulator<>::scoped_run BOOST_JOIN(_boost_chrono_stopclock_accumulator_run_, __LINE__)(BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__))
 
 #define BOOST_CHRONO_STOPCLOCK_ACCUMULATOR_FCT_REVERSE \
     static stopclock_accumulator<> BOOST_JOIN(_boost_chrono_stopclock_accumulator_, __LINE__)( \

Modified: sandbox/chrono/libs/chrono/example/scoped_stopwatch_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/scoped_stopwatch_example.cpp (original)
+++ sandbox/chrono/libs/chrono/example/scoped_stopwatch_example.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -14,12 +14,13 @@
 using namespace boost::chrono;
 double res;
 void f1(long j)
-{
+{
     stopwatch<>::reporter _(BOOST_CHRONO_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::scoped_suspend s(_);
- boost::this_thread::sleep(boost::posix_time::milliseconds(200));
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10));
 
 }
 int main()
@@ -29,7 +30,7 @@
     res=0;
     for (long i =0; i< 3; ++i)
         f1(i*100);
-
+
     std::cout<< res << std::endl;
   return 0;
 }

Modified: sandbox/chrono/libs/chrono/example/specific_stopwatch_accumulator_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/specific_stopwatch_accumulator_example.cpp (original)
+++ sandbox/chrono/libs/chrono/example/specific_stopwatch_accumulator_example.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -9,24 +9,79 @@
 
 #include <boost/chrono/stopwatches.hpp>
 #include <cmath>
+#include <boost/accumulators/statistics/variance.hpp>
 
 using namespace boost::chrono;
 using namespace boost::accumulators;
-typedef stopwatch_accumulator<process_real_cpu_clock, kind::running,
+
+ 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)
+ {
+ typedef typename Stopwatch::accumulator accumulator_t;
+ typedef typename Stopwatch::duration duration_t;
+ accumulator_t& acc = stopwatch_.accumulated();
+
+ 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 << boost::chrono::duration<double>(duration_t(typename duration_t::rep(mean(acc)))).count();
+ 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,
             accumulator_set<process_real_cpu_clock::rep,
                 features<
                         tag::count,
                         tag::sum,
- tag::min,
- tag::max,
- tag::mean
+ tag::mean,
+ tag::variance(lazy)
>
>
- >::reporter my_stopwatch_accumulator_reporter;
+ >
+ , my_stopwatch_accumulator_formatter
+ > my_stopwatch_accumulator_reporter;
 
 int f1(long j)
 {
- static my_stopwatch_accumulator_reporter acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
+ //static my_stopwatch_accumulator_reporter acc(BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT);
+ static my_stopwatch_accumulator_reporter acc;
   my_stopwatch_accumulator_reporter::scoped_run _(acc);
 
   for ( long i = 0; i < j; ++i )
@@ -36,6 +91,7 @@
 }
 int main()
 {
+ static my_stopwatch_accumulator_reporter acc;
 
   f1(100000);
   f1(200000);

Modified: sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp (original)
+++ sandbox/chrono/libs/chrono/example/stopclock_accumulator_example.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -8,7 +8,10 @@
 // See http://www.boost.org/libs/chrono for documentation.
 
 #include <boost/chrono/stopclock_accumulator.hpp>
+//#include <boost/chrono/stopwatches.hpp>
+
 #include <cmath>
+#include <boost/thread.hpp>
 
 using namespace boost::chrono;
 int f1(long j)
@@ -18,6 +21,8 @@
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
+ boost::this_thread::sleep(boost::posix_time::milliseconds(20));
+
 
   return 0;
 }

Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -108,8 +108,10 @@
         [ run ../example/specific_stopwatch_accumulator_example.cpp : : : <library>/boost/system//boost_system : specific_stopwatch_accumulator_example_dll ]
         [ run ../example/stopclock_example.cpp : : : <link>static ]
         [ run ../example/stopclock_example.cpp : : : <library>/boost/system//boost_system : stopclock_example_dll ]
- [ run ../example/stopclock_accumulator_example.cpp : : : <link>static ]
- [ run ../example/stopclock_accumulator_example.cpp : : : <library>/boost/system//boost_system : stopclock_accumulator_example_dll ]
+ [ run ../example/stopclock_accumulator_example.cpp : : : <library>/boost/thread//boost_thread <link>static ]
+ [ run ../example/stopclock_accumulator_example.cpp : : : <library>/boost/thread//boost_thread <library>/boost/system//boost_system : stopclock_accumulator_example_dll ]
+ [ run ../example/loop_stopclock_accumulator_example.cpp : : : <library>/boost/thread//boost_thread <link>static ]
+ [ run ../example/loop_stopclock_accumulator_example.cpp : : : <library>/boost/thread//boost_thread <library>/boost/system//boost_system : loop_stopclock_accumulator_example_dll ]
         [ run ../example/digital_time_example.cpp : : : <link>static ]
         [ run ../example/digital_time_example.cpp : : : <library>/boost/system//boost_system : digital_time_example_dll ]
         [ run ../example/scoped_stopclock_example.cpp : : : <link>static ]

Modified: sandbox/chrono/libs/chrono/test/test_duration.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/test_duration.cpp (original)
+++ sandbox/chrono/libs/chrono/test/test_duration.cpp 2010-01-24 12:14:38 EST (Sun, 24 Jan 2010)
@@ -180,6 +180,8 @@
 
     {
     double r = double(milliseconds(3) / milliseconds(3));
+ std::cout << r << '\n';
+
     duration<double, boost::milli> d = milliseconds(3) * 2.5;
     duration<double, boost::milli> d2 = 2.5 * milliseconds(3) ;
     duration<double, boost::milli> d3 = milliseconds(3) / 2.5;


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