Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75156 - trunk/libs/chrono/perf
From: vicente.botet_at_[hidden]
Date: 2011-10-28 10:52:27


Author: viboes
Date: 2011-10-28 10:52:26 EDT (Fri, 28 Oct 2011)
New Revision: 75156
URL: http://svn.boost.org/trac/boost/changeset/75156

Log:
Chrono: Added some perf tests
Added:
   trunk/libs/chrono/perf/is_leap.cpp (contents, props changed)
   trunk/libs/chrono/perf/no_check.cpp (contents, props changed)
Text files modified:
   trunk/libs/chrono/perf/Jamfile.v2 | 9 ++++++---
   trunk/libs/chrono/perf/store_now_in_vector.cpp | 3 ++-
   2 files changed, 8 insertions(+), 4 deletions(-)

Modified: trunk/libs/chrono/perf/Jamfile.v2
==============================================================================
--- trunk/libs/chrono/perf/Jamfile.v2 (original)
+++ trunk/libs/chrono/perf/Jamfile.v2 2011-10-28 10:52:26 EDT (Fri, 28 Oct 2011)
@@ -13,9 +13,10 @@
 
 project
     : requirements
- <target-os>freebsd:<threading>multi
- <target-os>linux:<threading>multi
- <toolset>pgi:<threading>multi
+ <target-os>freebsd:<linkflags>"-lrt"
+ <target-os>linux:<linkflags>"-lrt"
+ <toolset>pgi:<linkflags>"-lrt"
+ #<threading>single:<define>BOOST_CHRONO_THREAD_DISABLED
         <toolset>msvc:<asynch-exceptions>on
         <define>BOOST_CHRONO_USES_MPL_ASSERT
         <define>BOOST_SYSTEM_NO_DEPRECATED
@@ -164,5 +165,7 @@
     test-suite "perf"
         :
         [ chrono-run store_now_in_vector.cpp ]
+ [ chrono-run is_leap.cpp ]
+ [ chrono-run no_check.cpp ]
         ;
 

Added: trunk/libs/chrono/perf/is_leap.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/perf/is_leap.cpp 2011-10-28 10:52:26 EDT (Fri, 28 Oct 2011)
@@ -0,0 +1,101 @@
+// Copyright 2011 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/chrono_io.hpp>
+
+ static
+ const int
+ is_leap_table_[400] =
+ {
+ 1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,
+ 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,
+ 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,
+ 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0
+ };
+ /**
+ * is_leap could be made more efficient by using a table indexed by the y % 400.
+ * This table could contain true for y such as
+ * y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)
+ *
+ * is_leap = is_leap_table[y%400]
+ */
+ static
+ inline
+ bool
+ is_leap_calc(int y) BOOST_NOEXCEPT
+ {
+ return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
+ }
+
+
+ static
+ inline
+ bool
+ is_leap_table(int y) BOOST_NOEXCEPT
+ {
+ return (y % 4 == 0) && is_leap_table_[y%400];
+ //return (y & 3 == 0) && is_leap_table_[y%400];
+ }
+
+ static
+ inline
+ bool
+ is_leap(int y) BOOST_NOEXCEPT
+ {
+#if defined BOOST_CHRONO_IS_LEAP_USES_TABLE
+ return is_leap_table(y);
+#else
+ return is_leap_calc(y);
+#endif
+ }
+
+int main()
+{
+ typedef boost::chrono::high_resolution_clock Clock;
+ typedef boost::chrono::duration<double> sec;
+// for (int y = -32768; y <= 32767; ++y)
+// {
+// if (is_leap_calc(y)!=is_leap_table(y))
+// std::cout
+// << "is_leap_calc:" << is_leap_calc(y) << " "
+// << "is_leap_table:" << is_leap_table(y) << " "
+// << y << " " << y%400 <<"\n";
+//
+// }
+ {
+ int cnt=0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < 100; ++x)
+ for (int y = 0; y <= 32767; ++y)
+ //for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += is_leap_calc(y)?1:0;
+ }
+ Clock::time_point t1 = Clock::now();
+ std::cout << "is_leap_calc: " << t1-t0 << " " << cnt <<"\n";
+ }
+
+ {
+ int cnt=0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < 100; ++x)
+ for (int y = 0; y <= 32767; ++y)
+ //for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += is_leap_table(y)?1:0;
+ }
+ Clock::time_point t1 = Clock::now();
+ std::cout << "is_leap_table:" << t1-t0 << " " << cnt <<"\n";
+ }
+
+
+
+
+
+ return 0;
+
+
+}

Added: trunk/libs/chrono/perf/no_check.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/chrono/perf/no_check.cpp 2011-10-28 10:52:26 EDT (Fri, 28 Oct 2011)
@@ -0,0 +1,194 @@
+// Copyright 2011 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include <boost/chrono/chrono.hpp>
+#include <boost/chrono/chrono_io.hpp>
+#include <boost/chrono/date/date.hpp>
+
+using namespace boost::chrono;
+const int times = 100;
+int main()
+{
+ typedef boost::chrono::high_resolution_clock Clock;
+ typedef boost::chrono::duration<double> sec;
+ //////////////////////
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += y+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "none: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y,no_check);
+ cnt += year(y,no_check)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "no_check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y);
+ cnt += year(y)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << " check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ //////////////////////
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += y+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "none: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y,no_check);
+ cnt += year(y,no_check)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "no_check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y);
+ cnt += year(y)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << " check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ //////////////////////
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += y+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "none: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y,no_check);
+ cnt += year(y,no_check)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << "no_check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y);
+ cnt += year(y)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ std::cout << " check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ Clock::duration none_d;
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ cnt += y+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ none_d=t1 - t0;
+ std::cout << "none: " << t1 - t0 << " " << cnt << "\n";
+ }
+ Clock::duration no_check_d;
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y,no_check);
+ cnt += year(y,no_check)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ no_check_d=t1 - t0;
+ std::cout << "no_check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ Clock::duration check_d;
+ {
+ int cnt = 0;
+ Clock::time_point t0 = Clock::now();
+ for (int x = 0; x < times; ++x)
+ for (int y = -32768; y <= 32767; ++y)
+ {
+ //year aYear(y);
+ cnt += year(y)+x;
+ //if (cnt %4096==0) std::cout << cnt << " ";
+ }
+ //std::cout << std::endl;
+ Clock::time_point t1 = Clock::now();
+ check_d=t1 - t0;
+ std::cout << " check: " << t1 - t0 << " " << cnt << "\n";
+ }
+ std::cout << " check-none: " << (check_d-none_d) << "\n";
+ std::cout << " no_check-none: " << (no_check_d-none_d) << "\n";
+
+ return 1;
+
+}

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-28 10:52:26 EDT (Fri, 28 Oct 2011)
@@ -15,7 +15,8 @@
 #include <unistd.h>
 #endif
 
-static const std::size_t size = 10000000;
+//static const std::size_t size = 10000000;
+static const std::size_t size = 10000;
 
 typedef boost::chrono::simple_stopwatch<boost::chrono::high_resolution_clock> Stopwatch;
 typedef boost::chrono::stopwatch_reporter<Stopwatch> Reporter;


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