Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74352 - sandbox/stopwatches/libs/chrono/stopwatches/example
From: vicente.botet_at_[hidden]
Date: 2011-09-11 13:36:31


Author: viboes
Date: 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
New Revision: 74352
URL: http://svn.boost.org/trac/boost/changeset/74352

Log:
Stopwatches: prepare extraction of reporting
Text files modified:
   sandbox/stopwatches/libs/chrono/stopwatches/example/loop_stopclock_accumulator_example.cpp | 1 +
   sandbox/stopwatches/libs/chrono/stopwatches/example/nested_stopclock_accumulator_example.cpp | 1 +
   sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopclock_example.cpp | 1 +
   sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp | 23 +++++++++++++++++------
   sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp | 34 ++++++++++++++++++++++++++++------
   sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_example.cpp | 11 ++++++++---
   6 files changed, 56 insertions(+), 15 deletions(-)

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/loop_stopclock_accumulator_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/loop_stopclock_accumulator_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/loop_stopclock_accumulator_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -6,6 +6,7 @@
 
 //#include <boost/chrono/stopclock_accumulator.hpp>
 #include <boost/chrono/stopwatches/stopwatches.hpp>
+#include <boost/chrono/stopwatches/stopclock_accumulator.hpp>
 
 #include <cmath>
 #include "sleep_for.hpp"

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/nested_stopclock_accumulator_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/nested_stopclock_accumulator_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/nested_stopclock_accumulator_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -5,6 +5,7 @@
 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
 
 #include <boost/chrono/stopwatches.hpp>
+#include <boost/chrono/stopwatches/stopclock_accumulator.hpp>
 #include <cmath>
 #include "sleep_for.hpp"
 

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopclock_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopclock_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopclock_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -5,6 +5,7 @@
 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
 
 #include <boost/chrono/stopwatches/stopwatches.hpp>
+#include <boost/chrono/stopwatches/scoped_stopclock.hpp>
 #include <cmath>
 
 using namespace boost::chrono;

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/scoped_stopwatch_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -7,29 +7,40 @@
 #include <boost/chrono/stopwatches/stopwatches.hpp>
 #include <cmath>
 #include "sleep_for.hpp"
+#include <boost/chrono/chrono_io.hpp>
+//#include <iostream>
 
 using namespace boost::chrono;
 
 long double res;
 void f1(long j)
 {
- stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ //stopwatch<> sw;
     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));
+ //stopwatch_reporter<stopwatch<> >::scoped_suspend s(_);
+ //std::cout << "f1("<< j <<") Elapsed time: " << sw.elapsed() << std::endl;
 
 }
 int main()
 {
- stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ stopwatch<> sw;
 
     res=0;
- for (long i =0; i< 3; ++i) {
- f1(i*100);
+ for (long i =1; i< 4; ++i) {
+ stopwatch<> sw;
+ f1(i*1000);
+ {
+ stopwatch_suspender<stopwatch<> > _(sw);
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(10));
+ }
+ std::cout << "f1("<< i*1000 <<") Elapsed time: " << sw.elapsed() << std::endl;
     }
 
     std::cout<< res << std::endl;
+ std::cout << "main() Elapsed time: " << sw.elapsed() << std::endl;
   return 0;
 }

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_accumulator_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -4,16 +4,27 @@
 // See http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org/libs/chrono for documentation.
 
+#include <boost/chrono/chrono_io.hpp>
 #include <boost/chrono/stopwatches/stopwatches.hpp>
+//#include <boost/chrono/process_cpu_clocks.hpp>
 #include <cmath>
 
 
 using namespace boost::chrono;
+using namespace boost;
 
-int f1(long j)
+
+
+//typedef stopwatch_accumulator<process_real_cpu_clock> swa;
+typedef stopwatch_accumulator<high_resolution_clock> swa;
+int f1(long j, swa& sw)
 {
- 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);
+ //static stopwatch_reporter<stopwatch_accumulator<high_resolution_clock> > acc(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch_accumulator<high_resolution_clock> >::scoped_run r_(acc);
+ //static stopwatch_reporter<stopwatch_accumulator<process_real_cpu_clock> > acc2(BOOST_STOPWATCHES_ACCUMULATOR_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch_accumulator<process_real_cpu_clock> >::scoped_run r2_(acc2);
+
+ stopwatch_runner<swa > _(sw);
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
@@ -22,9 +33,20 @@
 }
 int main()
 {
+ swa sw;
 
- f1(1000);
- f1(2000);
- f1(3000);
+ f1(10000000,sw);
+ f1(20000000,sw);
+ f1(30000000,sw);
+
+ swa::accumulator_set& acc = sw.get_storage();
+ std::cout << "f1() Lifetime: " << sw.lifetime() << std::endl;
+ std::cout << "f1() Elapsed: " << sw.elapsed() << std::endl;
+ std::cout << "f1() Count: " << accumulators::count(acc) << std::endl;
+ std::cout << "f1() Sum: " << accumulators::sum(acc) << std::endl;
+ std::cout << "f1() Sum/Count: " << accumulators::sum(acc)/accumulators::count(acc) << std::endl;
+ std::cout << "f1() Mean: " << accumulators::mean(acc) << std::endl;
+ std::cout << "f1() Min: " << (accumulators::min)(acc) << std::endl;
+ std::cout << "f1() Max: " << (accumulators::max)(acc) << std::endl;
   return 0;
 }

Modified: sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_example.cpp
==============================================================================
--- sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_example.cpp (original)
+++ sandbox/stopwatches/libs/chrono/stopwatches/example/stopwatch_example.cpp 2011-09-11 13:36:30 EDT (Sun, 11 Sep 2011)
@@ -5,27 +5,32 @@
 // See http://www.boost.org/LICENSE_1_0.txt
 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
 
-#include <iostream>
+//#include <iostream>
 #include <boost/chrono/stopwatches/stopwatches.hpp>
+#include <boost/chrono/chrono_io.hpp>
 #include <cmath>
 
 using namespace boost::chrono;
 
 int f1(long j)
 {
- stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ stopwatch<> sw;
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
 
+ std::cout << "f1("<< j <<") Elapsed time: " << sw.elapsed() << std::endl;
   return 0;
 }
 int main()
 {
- stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ //stopwatch_reporter<stopwatch<> > _(BOOST_STOPWATCHES_STOPWATCH_FUNCTION_FORMAT);
+ stopwatch<> sw;
 
   f1(1000);
   f1(2000);
   f1(3000);
+ std::cout << "main() Elapsed time: " << sw.elapsed() << std::endl;
   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