Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74682 - trunk/libs/chrono/perf
From: vicente.botet_at_[hidden]
Date: 2011-10-03 17:15:37


Author: viboes
Date: 2011-10-03 17:15:36 EDT (Mon, 03 Oct 2011)
New Revision: 74682
URL: http://svn.boost.org/trac/boost/changeset/74682

Log:
Chrono: update perf test with process_cpu_clock
Text files modified:
   trunk/libs/chrono/perf/store_now_in_vector.cpp | 84 +++++++++++++++++++++++++--------------
   1 files changed, 53 insertions(+), 31 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-03 17:15:36 EDT (Mon, 03 Oct 2011)
@@ -8,75 +8,92 @@
 #include <boost/chrono/stopwatches/simple_stopwatch.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <vector>
+
+#if 0
 #include <sys/time.h> //for gettimeofday and timeval
 #include <sys/times.h> //for times
 #include <unistd.h>
+#endif
 
 static const std::size_t size = 10000000;
 
+typedef boost::chrono::simple_stopwatch<boost::chrono::high_resolution_clock> Stopwatch;
+typedef boost::chrono::stopwatch_reporter<Stopwatch> Reporter;
+
+template <typename Clock>
+void perf_constant(std::vector<typename Clock::time_point>& vec)
+{
+ for (int i=size-1; i>=0; --i)
+ {
+ vec[i]=typename Clock::time_point();
+ }
+}
+
 template <typename Clock>
 void perf(std::vector<typename Clock::time_point>& vec)
 {
- typedef boost::chrono::stopwatch_reporter<boost::chrono::simple_stopwatch<boost::chrono::high_resolution_clock> > Reporter;
- Reporter rp;
   for (int i=size-1; i>=0; --i)
   {
     vec[i]=Clock::now();
- //vec[i]=typename Clock::time_point(typename Clock::time_point::duration(i));
   }
 }
 
+template <typename Clock>
+void test()
+{
+ std::vector<typename Clock::time_point> vec(size);
+ Stopwatch sw1;
+ perf_constant<Clock>(vec);
+ Stopwatch::duration t1 = sw1.elapsed();
+ Stopwatch sw2;
+ perf<Clock>(vec);
+ Stopwatch::duration t2 = sw2.elapsed();
+ std::cout <<" "<< (t2-t1)/size << std::endl;
+ std::size_t cnt=0;
+ for (int i=size-1; i>0; --i)
+ {
+ if (vec[i]!=vec[i-1]) ++cnt;
+ }
+ std::cout <<"changes: "<< cnt << std::endl;
+
+}
+
+
+
+
+
+#if 0
 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-1; 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-1; i>=0; --i)
   {
     vec[i]=::clock();
- //vec[i]=typename Clock::time_point(typename Clock::time_point::duration(i));
   }
 }
 
-
-template <typename Clock>
-void test()
-{
- std::vector<typename Clock::time_point> vec(size);
- perf<Clock>(vec);
- std::size_t cnt=0;
- for (int i=size-1; i>1; --i)
- {
- if (vec[i]==vec[i-1]) ++cnt;
- }
- std::cout <<"Nb of values eq to preceding: "<< cnt << std::endl;
- std::cout <<"Diff last-first: "<< boost::chrono::duration_cast<boost::chrono::milliseconds>(vec[0]-vec[size-1]) << std::endl;
-
-}
 void test2()
 {
   std::vector<clock_t> vec(size);
   perf2(vec);
   std::size_t cnt=0;
- for (int i=10; i>1; --i)
+ for (int i=10; i>0; --i)
   {
- if (vec[i]==vec[i-1]) ++cnt;
+ if (vec[i]!=vec[i-1]) ++cnt;
     std::cout << vec[i] << " " ;
   }
   std::cout<< std::endl;
- std::cout <<"Nb of values eq to preceding: "<< cnt << std::endl;
- std::cout <<"Diff last-first: "<< vec[0]-vec[size-1] << std::endl;
+ std::cout <<"changes: "<< cnt << std::endl;
 }
 
 void test3()
@@ -84,16 +101,17 @@
   std::vector<clock_t> vec(size);
   perf3(vec);
   std::size_t cnt=0;
- for (int i=10; i>1; --i)
+ for (int i=10; i>0; --i)
   {
- if (vec[i]==vec[i-1]) ++cnt;
+ if (vec[i]!=vec[i-1]) ++cnt;
     std::cout << vec[i] << " " ;
   }
   std::cout<< std::endl;
- std::cout <<"Nb of values eq to preceding: "<< cnt << std::endl;
- std::cout <<"Diff last-first: "<< vec[0]-vec[size-1] << std::endl;
+ std::cout <<"changes: "<< cnt << std::endl;
 }
 
+#endif
+
 int main() {
 
   std::cout << "system_clock ";
@@ -112,11 +130,15 @@
   test<boost::chrono::process_user_cpu_clock>();
   std::cout << "process_system_cpu_clock " ;
   test<boost::chrono::process_system_cpu_clock>();
+ std::cout << "process_cpu_clock " ;
+ test<boost::chrono::process_cpu_clock>();
 #endif
 
+#if 0
   std::cout << "times ";
   test2();
   std::cout << "clock ";
   test3();
- return 1;
+#endif
+ 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