BIND 10 master, updated. ceaa247d89ac7d97594572bc17f005144c5efb8d [master] Merge branch 'trac1773new'

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Apr 4 22:29:14 UTC 2012


The branch, master has been updated
       via  ceaa247d89ac7d97594572bc17f005144c5efb8d (commit)
       via  fe9349ae3a6f283089af635b2453f3b7a6c66ac6 (commit)
       via  cc73f7e20f8534b0986bcc9a41e99511109546d7 (commit)
       via  1c45a4e0bc84ab2d3e006ceb63ce18b9c32adf53 (commit)
      from  dddc267e555071b02a90623758f947d18c46356c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ceaa247d89ac7d97594572bc17f005144c5efb8d
Merge: dddc267 fe9349a
Author: JINMEI Tatuya <jinmei at isc.org>
Date:   Wed Apr 4 15:28:29 2012 -0700

    [master] Merge branch 'trac1773new'

-----------------------------------------------------------------------

Summary of changes:
 src/lib/bench/benchmark.h                 |   52 ++++++++++++++++------------
 src/lib/bench/example/search_bench.cc     |    4 +-
 src/lib/bench/tests/benchmark_unittest.cc |    8 ++--
 3 files changed, 36 insertions(+), 28 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/bench/benchmark.h b/src/lib/bench/benchmark.h
index 7f77aa1..a5c6fd4 100644
--- a/src/lib/bench/benchmark.h
+++ b/src/lib/bench/benchmark.h
@@ -17,6 +17,7 @@
 
 #include <sys/time.h>
 
+#include <cassert>
 #include <iostream>
 #include <ios>
 
@@ -210,9 +211,9 @@ public:
     /// \param target The templated class object that
     /// implements the code to be benchmarked.
     BenchMark(const int iterations, T target) :
-        iterations_(iterations), sub_iterations_(0), target_(target)
+        iterations_(iterations), sub_iterations_(0), target_(NULL)
     {
-        initialize(true);
+        initialize(target, true);
     }
 
     /// \brief Constructor for finer-grained control.
@@ -230,9 +231,9 @@ public:
     /// \param immediate If \c true the benchmark will be performed within
     /// the constructor; otherwise it only does initialization.
     BenchMark(const int iterations, T& target, const bool immediate) :
-        iterations_(iterations), sub_iterations_(0), target_(target)
+        iterations_(iterations), sub_iterations_(0), target_(&target)
     {
-        initialize(immediate);
+        initialize(target, immediate);
     }
     //@}
 
@@ -240,15 +241,17 @@ public:
     ///
     /// This method will be called from \c run() before starting the benchmark.
     /// By default it's empty, but can be customized via template
-    /// specialization.
-    void setUp() {}
+    /// specialization.  When specialized, a reference to the target object
+    /// given to the constructor will be passed to the implementation.
+    void setUp(T&) {}
 
     /// \brief Hook to be called after benchmark.
     ///
     /// This method will be called from \c run() when the benchmark completes.
     /// By default it's empty, but can be customized via template
-    /// specialization.
-    void tearDown() {}
+    /// specialization.  When specialized, a reference to the target object
+    /// given to the constructor will be passed to the implementation.
+    void tearDown(T&) {}
 
     /// \brief Perform benchmark.
     ///
@@ -257,17 +260,8 @@ public:
     /// of times specified on construction, and records the time on completion.
     /// Finally, it calls \c tearDown().
     void run() {
-        setUp();
-
-        struct timeval beg, end;
-        gettimeofday(&beg, NULL);
-        for (unsigned int i = 0; i < iterations_; ++i) {
-            sub_iterations_ += target_.run();
-        }
-        gettimeofday(&end, NULL);
-        tv_diff_ = tv_subtract(end, beg);
-
-        tearDown();
+        assert(target_ != NULL);
+        run(*target_);
     }
 
     /// \brief Print the benchmark result.
@@ -361,9 +355,23 @@ public:
     /// performed implicitly.
     static const int ITERATION_FAILURE = -1;
 private:
-    void initialize(const bool immediate) {
+    void run(T& target) {
+        setUp(target);
+
+        struct timeval beg, end;
+        gettimeofday(&beg, NULL);
+        for (unsigned int i = 0; i < iterations_; ++i) {
+            sub_iterations_ += target.run();
+        }
+        gettimeofday(&end, NULL);
+        tv_diff_ = tv_subtract(end, beg);
+
+        tearDown(target);
+    }
+
+    void initialize(T& target, const bool immediate) {
         if (immediate) {
-            run();
+            run(target);
             printResult();
         }
     }
@@ -388,7 +396,7 @@ private:
     static const int ONE_MILLION = 1000000;
     const unsigned int iterations_;
     unsigned int sub_iterations_;
-    T& target_;
+    T* target_;
     struct timeval tv_diff_;
 };
 
diff --git a/src/lib/bench/example/search_bench.cc b/src/lib/bench/example/search_bench.cc
index 851d815..84f95d9 100644
--- a/src/lib/bench/example/search_bench.cc
+++ b/src/lib/bench/example/search_bench.cc
@@ -79,9 +79,9 @@ namespace isc {
 namespace bench {
 template<>
 void
-BenchMark<SetSearchBenchMark>::setUp() {
+BenchMark<SetSearchBenchMark>::setUp(SetSearchBenchMark& target) {
     cout << "Benchmark for searching std::set (size="
-         << target_.data_.size() << ")" << endl;    
+         << target.data_.size() << ")" << endl;
 }
 }
 }
diff --git a/src/lib/bench/tests/benchmark_unittest.cc b/src/lib/bench/tests/benchmark_unittest.cc
index 9b476cd..dfe7df9 100644
--- a/src/lib/bench/tests/benchmark_unittest.cc
+++ b/src/lib/bench/tests/benchmark_unittest.cc
@@ -46,14 +46,14 @@ namespace isc {
 namespace bench {
 template <>
 void
-BenchMark<TestBenchMark>::setUp() {
-    target_.setup_completed_ = true;
+BenchMark<TestBenchMark>::setUp(TestBenchMark& target) {
+    target.setup_completed_ = true;
 };
 
 template <>
 void
-BenchMark<TestBenchMark>::tearDown() {
-    target_.teardown_completed_ = true;
+BenchMark<TestBenchMark>::tearDown(TestBenchMark& target) {
+    target.teardown_completed_ = true;
 };
 
 // XXX: some compilers cannot find class static constants used in



More information about the bind10-changes mailing list