Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55088 - in trunk/libs/spirit/benchmarks: . qi
From: joel_at_[hidden]
Date: 2009-07-22 16:09:07


Author: djowel
Date: 2009-07-22 16:09:06 EDT (Wed, 22 Jul 2009)
New Revision: 55088
URL: http://svn.boost.org/trac/boost/changeset/55088

Log:
Updates to benchmark harness
Text files modified:
   trunk/libs/spirit/benchmarks/boiler_plate.cpp | 4 ++--
   trunk/libs/spirit/benchmarks/measure.hpp | 30 ++++++++++++++++++------------
   trunk/libs/spirit/benchmarks/qi/uint_parser.cpp | 40 ++++++++++++++++++++++++++--------------
   3 files changed, 46 insertions(+), 28 deletions(-)

Modified: trunk/libs/spirit/benchmarks/boiler_plate.cpp
==============================================================================
--- trunk/libs/spirit/benchmarks/boiler_plate.cpp (original)
+++ trunk/libs/spirit/benchmarks/boiler_plate.cpp 2009-07-22 16:09:06 EDT (Wed, 22 Jul 2009)
@@ -10,9 +10,9 @@
 {
     struct f
     {
- void benchmark(int x)
+ void benchmark()
         {
- this->val += x; // Here is where you put code that you want
+ this->val += 5; // Here is where you put code that you want
                             // to benchmark. Make sure it returns something.
                             // Anything.
         }

Modified: trunk/libs/spirit/benchmarks/measure.hpp
==============================================================================
--- trunk/libs/spirit/benchmarks/measure.hpp (original)
+++ trunk/libs/spirit/benchmarks/measure.hpp 2009-07-22 16:09:06 EDT (Wed, 22 Jul 2009)
@@ -25,8 +25,7 @@
     // sure it's needed.
     int live_code;
 
- // Call objects of the given Accumulator type repeatedly with x as
- // an argument.
+ // Call objects of the given Accumulator type repeatedly
     template <class Accumulator>
     void hammer(long const repeats)
     {
@@ -52,7 +51,6 @@
         // this array. 1024 is an upper limit on the pipeline depth of
         // current vector machines.
         
- int x = 0;
         const std::size_t number_of_accumulators = 1024;
         live_code = 0; // reset to zero
 
@@ -62,7 +60,7 @@
         {
             for (Accumulator* ap = a; ap < a + number_of_accumulators; ++ap)
             {
- ap->benchmark(x);
+ ap->benchmark();
             }
         }
 
@@ -74,8 +72,7 @@
         }
     }
 
- // Measure the time required to hammer accumulators of the given
- // type with the argument x.
+ // Measure the time required to hammer accumulators of the given type
     template <class Accumulator>
     double measure(long const repeats)
     {
@@ -93,17 +90,26 @@
         return time.elapsed() / repeats; // return the time of one iteration
     }
     
+ template <class Accumulator>
+ void report(char const* name, long const repeats)
+ {
+ std::cout.precision(10);
+ std::cout << name << ": ";
+ for (int i = 0; i < (20-strlen(name)); ++i)
+ std::cout << ' ';
+ std::cout << std::fixed << test::measure<Accumulator>(repeats) << " [s] ";
+ Accumulator acc;
+ acc.benchmark();
+ std::cout << std::hex << "{checksum: " << acc.val << "}";
+ std::cout << std::flush << std::endl;
+ }
+
 #define BOOST_SPIRIT_TEST_HAMMER(r, data, elem) \
     test::hammer<elem>(repeats);
     /***/
 
 #define BOOST_SPIRIT_TEST_MEASURE(r, data, elem) \
- std::cout.precision(10); \
- std::cout \
- << BOOST_PP_STRINGIZE(elem) << ": " \
- << std::fixed \
- << test::measure<elem>(repeats) \
- << " [s]" << std::flush << std::endl;
+ test::report<elem>(BOOST_PP_STRINGIZE(elem), repeats); \
     /***/
 
 #define BOOST_SPIRIT_TEST_BENCHMARK(max_repeats, FSeq) \

Modified: trunk/libs/spirit/benchmarks/qi/uint_parser.cpp
==============================================================================
--- trunk/libs/spirit/benchmarks/qi/uint_parser.cpp (original)
+++ trunk/libs/spirit/benchmarks/qi/uint_parser.cpp 2009-07-22 16:09:06 EDT (Wed, 22 Jul 2009)
@@ -12,6 +12,7 @@
 
 namespace
 {
+ ///////////////////////////////////////////////////////////////////////////
     // Random number string generator
     std::string
     gen_int(int digits)
@@ -33,7 +34,8 @@
     ///////////////////////////////////////////////////////////////////////////
     struct atoi_test
     {
- void benchmark(int x)
+ atoi_test() : val(0) {}
+ void benchmark()
         {
             this->val += atoi(first[0]);
             this->val += atoi(first[1]);
@@ -51,8 +53,9 @@
     
     ///////////////////////////////////////////////////////////////////////////
     struct strtol_test
- {
- void benchmark(int x)
+ {
+ strtol_test() : val(0) {}
+ void benchmark()
         {
             this->val += strtol(first[0], const_cast<char**>(&last[0]), 10);
             this->val += strtol(first[1], const_cast<char**>(&last[1]), 10);
@@ -71,21 +74,30 @@
     ///////////////////////////////////////////////////////////////////////////
     struct spirit_int_test
     {
- void benchmark(int x)
+ static int parse(char const* first, char const* last)
+ {
+ int n;
+ namespace qi = boost::spirit::qi;
+ using qi::int_;
+ qi::parse(first, last, int_, n);
+ return n;
+ }
+
+ spirit_int_test() : val(0) {}
+ void benchmark()
         {
             namespace qi = boost::spirit::qi;
             using qi::int_;
- int n;
             
- qi::parse(first[0], last[0], int_, n); this->val += n;
- qi::parse(first[1], last[1], int_, n); this->val += n;
- qi::parse(first[2], last[2], int_, n); this->val += n;
- qi::parse(first[3], last[3], int_, n); this->val += n;
- qi::parse(first[4], last[4], int_, n); this->val += n;
- qi::parse(first[5], last[5], int_, n); this->val += n;
- qi::parse(first[6], last[6], int_, n); this->val += n;
- qi::parse(first[7], last[7], int_, n); this->val += n;
- qi::parse(first[8], last[8], int_, n); this->val += n;
+ this->val += parse(first[0], last[0]);
+ this->val += parse(first[1], last[1]);
+ this->val += parse(first[2], last[2]);
+ this->val += parse(first[3], last[3]);
+ this->val += parse(first[4], last[4]);
+ this->val += parse(first[5], last[5]);
+ this->val += parse(first[6], last[6]);
+ this->val += parse(first[7], last[7]);
+ this->val += parse(first[8], last[8]);
         }
 
         int val; // This is needed to avoid dead-code elimination


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