Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74653 - trunk/libs/chrono/perf
From: vicente.botet_at_[hidden]
Date: 2011-10-02 14:08:24


Author: viboes
Date: 2011-10-02 14:08:24 EDT (Sun, 02 Oct 2011)
New Revision: 74653
URL: http://svn.boost.org/trac/boost/changeset/74653

Log:
Chrono: update perf with times() and clock()
Text files modified:
   trunk/libs/chrono/perf/store_now_in_vector.cpp | 57 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 57 insertions(+), 0 deletions(-)

Modified: trunk/libs/chrono/perf/store_now_in_vector.cpp
==============================================================================
--- trunk/libs/chrono/perf/store_now_in_vector.cpp (original)
+++ trunk/libs/chrono/perf/store_now_in_vector.cpp 2011-10-02 14:08:24 EDT (Sun, 02 Oct 2011)
@@ -6,7 +6,11 @@
 #include <boost/chrono/chrono.hpp>
 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
+#include <boost/chrono/process_cpu_clocks.hpp>
 #include <vector>
+#include <sys/time.h> //for gettimeofday and timeval
+#include <sys/times.h> //for times
+#include <unistd.h>
 
 static const std::size_t size = 1000000;
 
@@ -22,6 +26,30 @@
   }
 }
 
+void perf2(std::vector<clock_t>& vec)
+{
+ typedef boost::chrono::stopwatch_reporter<boost::chrono::simple_stopwatch<boost::chrono::high_resolution_clock> > Reporter;
+ Reporter rp;
+ for (int i=size; i>0; --i)
+ {
+ tms tm;
+ vec[i]=::times(&tm);
+ //vec[i]=typename Clock::time_point(typename Clock::time_point::duration(i));
+ }
+}
+
+void perf3(std::vector<clock_t>& vec)
+{
+ typedef boost::chrono::stopwatch_reporter<boost::chrono::simple_stopwatch<boost::chrono::high_resolution_clock> > Reporter;
+ Reporter rp;
+ for (int i=size; i>0; --i)
+ {
+ vec[i]=::clock();
+ //vec[i]=typename Clock::time_point(typename Clock::time_point::duration(i));
+ }
+}
+
+
 template <typename Clock>
 void test()
 {
@@ -34,6 +62,33 @@
   }
   std::cout << cnt << std::endl;
 }
+void test2()
+{
+ std::vector<clock_t> vec(size);
+ perf2(vec);
+ std::size_t cnt=0;
+ for (int i=10; i>1; --i)
+ {
+ if (vec[i]==vec[i-1]) ++cnt;
+ std::cout << vec[i] << " " ;
+ }
+ std::cout<< std::endl;
+ std::cout << cnt << std::endl;
+}
+
+void test3()
+{
+ std::vector<clock_t> vec(size);
+ perf3(vec);
+ std::size_t cnt=0;
+ for (int i=10; i>1; --i)
+ {
+ if (vec[i]==vec[i-1]) ++cnt;
+ std::cout << vec[i] << " " ;
+ }
+ std::cout<< std::endl;
+ std::cout << cnt << std::endl;
+}
 
 int main() {
 
@@ -45,5 +100,7 @@
   test<boost::chrono::process_real_cpu_clock>();
 #endif
   test<boost::chrono::high_resolution_clock>();
+ test2();
+ test3();
   return 1;
 }


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