Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59385 - in sandbox/chrono/libs/chrono: example test
From: vicente.botet_at_[hidden]
Date: 2010-01-31 17:12:47


Author: viboes
Date: 2010-01-31 17:12:47 EST (Sun, 31 Jan 2010)
New Revision: 59385
URL: http://svn.boost.org/trac/boost/changeset/59385

Log:
Boost.Chrono: Version 0.4.0,
* Fix bug on timeval_demo.
    time_point t(duration(xtime(0))); // this was taken as a function declaration
    gettimeofday((timeval*)&t, 0);
    return t;
by
    timeval tv;
    gettimeofday(&tv, 0);
    xtime xt( tv.tv_sec, tv.tv_usec);
    return time_point(duration(xt));

* Fix bug on run_timer_test (add a global variable to avoid optimization that removes completely the code to be measured

Text files modified:
   sandbox/chrono/libs/chrono/example/timeval_demo.cpp | 16 +++++++++-------
   sandbox/chrono/libs/chrono/test/run_timer_test.cpp | 12 +++++++-----
   2 files changed, 16 insertions(+), 12 deletions(-)

Modified: sandbox/chrono/libs/chrono/example/timeval_demo.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/example/timeval_demo.cpp (original)
+++ sandbox/chrono/libs/chrono/example/timeval_demo.cpp 2010-01-31 17:12:47 EST (Sun, 31 Jan 2010)
@@ -169,15 +169,17 @@
 xtime_clock::now()
 {
 #if defined(BOOST_CHRONO_WINDOWS_API)
- time_point t(duration(xtime(0)));
- gettimeofday((timeval*)&t, 0);
- return t;
+ timeval tv;
+ gettimeofday(&tv, 0);
+ xtime xt( tv.tv_sec, tv.tv_usec);
+ return time_point(duration(xt));
 
 #elif defined(BOOST_CHRONO_MAC_API)
 
- time_point t(duration(xtime(0)));
- gettimeofday((timeval*)&t, 0);
- return t;
+ timeval tv;
+ gettimeofday(&tv, 0);
+ xtime xt( tv.tv_sec, tv.tv_usec);
+ return time_point(duration(xt));
 
 #elif defined(BOOST_CHRONO_POSIX_API)
     //time_point t(0,0);
@@ -187,7 +189,6 @@
 
     xtime xt( ts.tv_sec, ts.tv_nsec/1000);
     return time_point(duration(xt));
-
 #endif // POSIX
 
 }
@@ -201,6 +202,7 @@
     std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n';
     xtime_clock::duration delay(milliseconds(5));
     xtime_clock::time_point start = xtime_clock::now();
+
     while (xtime_clock::now() - start <= delay)
     {
     }

Modified: sandbox/chrono/libs/chrono/test/run_timer_test.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/run_timer_test.cpp (original)
+++ sandbox/chrono/libs/chrono/test/run_timer_test.cpp 2010-01-31 17:12:47 EST (Sun, 31 Jan 2010)
@@ -183,10 +183,10 @@
     std::cout << "process_timer_test..." << std::flush;
 
     boost::chrono::process_timer t;
-
+ double res; // avoids optimization
     for (long i = 0; i < 10000000L; ++i)
     {
- std::sqrt( static_cast<double>(i) );
+ res+=std::sqrt( static_cast<double>(i) ); // avoids optimization
     }
 
     boost::chrono::process_times times;
@@ -200,12 +200,14 @@
     std::cout << "\n";
 
     std::cout << times.real.count() << " times.real\n";
+ std::cout << times.user.count() << " times.user\n";
+ std::cout << times.system.count() << " times.system\n";
+ std::cout << (times.user+times.system).count() << " times.user+system\n";
     BOOST_CHECK( times.real > ns(1) );
 
- std::cout << times.user.count() << " times.user\n";
- BOOST_CHECK( times.user > ns(1) );
+ BOOST_CHECK( times.user+times.system > ns(1) );
 
- std::cout << "complete" << std::endl;
+ std::cout << "complete " << res << std::endl;
   }
 }
 


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