Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74526 - trunk/libs/chrono/example
From: vicente.botet_at_[hidden]
Date: 2011-09-22 17:53:27


Author: viboes
Date: 2011-09-22 17:53:25 EDT (Thu, 22 Sep 2011)
New Revision: 74526
URL: http://svn.boost.org/trac/boost/changeset/74526

Log:
Chrono: added traces to try to catch some errors on Solaris
Text files modified:
   trunk/libs/chrono/example/lightweight_stopwatch_reporter_example.cpp | 10 ++++++++++
   trunk/libs/chrono/example/rounding.cpp | 19 +++++++++----------
   trunk/libs/chrono/example/stopwatch_example.cpp | 24 +++++++++++++++++++++---
   trunk/libs/chrono/example/stopwatch_reporter_example.cpp | 8 ++++++++
   4 files changed, 48 insertions(+), 13 deletions(-)

Modified: trunk/libs/chrono/example/lightweight_stopwatch_reporter_example.cpp
==============================================================================
--- trunk/libs/chrono/example/lightweight_stopwatch_reporter_example.cpp (original)
+++ trunk/libs/chrono/example/lightweight_stopwatch_reporter_example.cpp 2011-09-22 17:53:25 EDT (Thu, 22 Sep 2011)
@@ -6,6 +6,7 @@
 // See http://www.boost.org/libs/chrono/stopwatches for documentation.
 
 //#include <iostream>
+#include <boost/chrono/stopwatches/basic_stopwatch.hpp>
 #include <boost/chrono/stopwatches/reporters/lightweight_stopwatch_reporter.hpp>
 #include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
 #include <boost/chrono/chrono_io.hpp>
@@ -18,20 +19,29 @@
 int f1(long j)
 {
 
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   lightweight_stopwatch_reporter<simple_stopwatch<> > sw(fmtr);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
 
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   return 0;
 }
 int main()
 {
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   lightweight_stopwatch_reporter<simple_stopwatch<> > sw(fmtr);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
 
   f1(1000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   f1(2000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   f1(3000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   f1(4000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   return 0;
 }

Modified: trunk/libs/chrono/example/rounding.cpp
==============================================================================
--- trunk/libs/chrono/example/rounding.cpp (original)
+++ trunk/libs/chrono/example/rounding.cpp 2011-09-22 17:53:25 EDT (Thu, 22 Sep 2011)
@@ -15,16 +15,15 @@
 
 int main()
 {
- using namespace boost::chrono;
- milliseconds ms(2500);
- std::cout << floor<seconds>(ms) << '\n';
- std::cout << round<seconds>(ms) << '\n';
- std::cout << ceil<seconds>(ms) << '\n';
- ms = milliseconds(2516);
- typedef duration<long, boost::ratio<1, 30> > frame_rate;
- std::cout << floor<frame_rate>(ms) << '\n';
- std::cout << round<frame_rate>(ms) << '\n';
- std::cout << ceil<frame_rate>(ms) << '\n';
+ boost::chrono::milliseconds ms(2500);
+ std::cout << boost::chrono::floor<boost::chrono::seconds>(ms) << '\n';
+ std::cout << boost::chrono::round<boost::chrono::seconds>(ms) << '\n';
+ std::cout << boost::chrono::ceil<boost::chrono::seconds>(ms) << '\n';
+ ms = boost::chrono::milliseconds(2516);
+ typedef boost::chrono::duration<long, boost::ratio<1, 30> > frame_rate;
+ std::cout << boost::chrono::floor<frame_rate>(ms) << '\n';
+ std::cout << boost::chrono::round<frame_rate>(ms) << '\n';
+ std::cout << boost::chrono::ceil<frame_rate>(ms) << '\n';
 
         return 0;
 }

Modified: trunk/libs/chrono/example/stopwatch_example.cpp
==============================================================================
--- trunk/libs/chrono/example/stopwatch_example.cpp (original)
+++ trunk/libs/chrono/example/stopwatch_example.cpp 2011-09-22 17:53:25 EDT (Thu, 22 Sep 2011)
@@ -8,27 +8,45 @@
 //#include <iostream>
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
 #include <boost/chrono/chrono_io.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
 #include <cmath>
 
 using namespace boost::chrono;
 
+namespace ex
+{
+ template<class Rep, class Period>
+ void sleep_for(const duration<Rep, Period>& d)
+ {
+ typedef high_resolution_clock Clock;
+ typename Clock::time_point go =
+ Clock::now() + d;
+ while (Clock::now() < go)
+ {
+ }
+ }
+}
+
 int f1(long j)
 {
- simple_stopwatch<> sw;
+ simple_stopwatch<process_cpu_clock> sw;
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
+ ex::sleep_for(milliseconds(100));
 
   std::cout << "f1("<< j <<") Elapsed time: " << sw.elapsed() << std::endl;
   return 0;
 }
 int main()
 {
- simple_stopwatch<> sw;
+ simple_stopwatch<process_cpu_clock> sw;
 
   f1(1000);
   f1(2000);
   f1(3000);
- std::cout << "main() Elapsed time: " << sw.elapsed() << std::endl;
+ std::cout << "main() Elapsed time: " << duration_cast<duration<process_times<double>,boost::ratio<1> > >(sw.elapsed()) << std::endl;
+ std::cout << "main() Elapsed time: " << duration_cast<duration<process_times<nanoseconds::rep>,boost::milli> >(sw.elapsed()) << std::endl;
+ //std::cout << "main() Elapsed time: " << sw.elapsed() << std::endl;
   return 0;
 }

Modified: trunk/libs/chrono/example/stopwatch_reporter_example.cpp
==============================================================================
--- trunk/libs/chrono/example/stopwatch_reporter_example.cpp (original)
+++ trunk/libs/chrono/example/stopwatch_reporter_example.cpp 2011-09-22 17:53:25 EDT (Thu, 22 Sep 2011)
@@ -15,19 +15,27 @@
 
 int f1(long j)
 {
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   stopwatch_reporter<simple_stopwatch<> > sw;
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
 
   for ( long i = 0; i < j; ++i )
     std::sqrt( 123.456L ); // burn some time
 
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   return 0;
 }
 int main()
 {
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   stopwatch_reporter<simple_stopwatch<> > sw;
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
 
   f1(1000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   f1(2000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl;
   f1(3000);
+ std::cout << __FILE__ << "[" << __LINE__ << "]" << 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