BIND 10 trac826, updated. b75b54a7626b03755b4680cbd24e5e9a7ef08d95 libbench

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jun 28 14:04:05 UTC 2012


The branch, trac826 has been updated
       via  b75b54a7626b03755b4680cbd24e5e9a7ef08d95 (commit)
      from  284dc18ec942163778072e8c26dfef96ae7a2a79 (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 b75b54a7626b03755b4680cbd24e5e9a7ef08d95
Author: Francis Dupont <fdupont at isc.org>
Date:   Thu Jun 28 16:03:54 2012 +0200

    libbench

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

Summary of changes:
 src/lib/bench/benchmark.h                 |   52 +++++++++++++++++------------
 src/lib/bench/benchmark_util.cc           |    9 +++--
 src/lib/bench/example/.gitignore          |    1 +
 src/lib/bench/example/search_bench.cc     |    4 +--
 src/lib/{acl => bench}/tests/.gitignore   |    0
 src/lib/bench/tests/Makefile.am           |    3 ++
 src/lib/bench/tests/benchmark_unittest.cc |   21 ++++++------
 src/lib/bench/tests/loadquery_unittest.cc |    4 ---
 8 files changed, 50 insertions(+), 44 deletions(-)
 create mode 100644 src/lib/bench/example/.gitignore
 copy src/lib/{acl => bench}/tests/.gitignore (100%)

-----------------------------------------------------------------------
diff --git a/src/lib/bench/benchmark.h b/src/lib/bench/benchmark.h
index f7a6677..34baa14 100644
--- a/src/lib/bench/benchmark.h
+++ b/src/lib/bench/benchmark.h
@@ -22,6 +22,7 @@
 #include <sys/time.h>
 #endif
 
+#include <cassert>
 #include <iostream>
 #include <ios>
 
@@ -237,9 +238,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.
@@ -257,9 +258,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);
     }
     //@}
 
@@ -267,15 +268,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.
     ///
@@ -284,17 +287,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.
@@ -388,9 +382,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();
         }
     }
@@ -415,7 +423,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/benchmark_util.cc b/src/lib/bench/benchmark_util.cc
index 9cf3b26..34356c8 100644
--- a/src/lib/bench/benchmark_util.cc
+++ b/src/lib/bench/benchmark_util.cc
@@ -61,8 +61,7 @@ loadQueryData(istream& input, BenchQueries& queries, const RRClass& qclass,
     string line;
     unsigned int linenum = 0;
     Message query_message(Message::RENDER);
-    OutputBuffer buffer(128); // this should be sufficiently large
-    MessageRenderer renderer(buffer);
+    MessageRenderer renderer;
     while (getline(input, line), !input.eof()) {
         ++linenum;
         if (input.bad() || input.fail()) {
@@ -99,9 +98,9 @@ loadQueryData(istream& input, BenchQueries& queries, const RRClass& qclass,
             renderer.clear();
             query_message.toWire(renderer);
             vector<unsigned char> query_data(
-                static_cast<const unsigned char*>(buffer.getData()),
-                static_cast<const unsigned char*>(buffer.getData()) +
-                buffer.getLength());
+                static_cast<const unsigned char*>(renderer.getData()),
+                static_cast<const unsigned char*>(renderer.getData()) +
+                renderer.getLength());
             queries.push_back(query_data);
         } catch (const Exception&) {
             if (strict) {
diff --git a/src/lib/bench/example/.gitignore b/src/lib/bench/example/.gitignore
new file mode 100644
index 0000000..eb3877d
--- /dev/null
+++ b/src/lib/bench/example/.gitignore
@@ -0,0 +1 @@
+/search_bench
diff --git a/src/lib/bench/example/search_bench.cc b/src/lib/bench/example/search_bench.cc
index 117a5d9..10d5fa8 100644
--- a/src/lib/bench/example/search_bench.cc
+++ b/src/lib/bench/example/search_bench.cc
@@ -88,9 +88,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/.gitignore b/src/lib/bench/tests/.gitignore
new file mode 100644
index 0000000..d6d1ec8
--- /dev/null
+++ b/src/lib/bench/tests/.gitignore
@@ -0,0 +1 @@
+/run_unittests
diff --git a/src/lib/bench/tests/Makefile.am b/src/lib/bench/tests/Makefile.am
index 3f8a678..fc5c3ae 100644
--- a/src/lib/bench/tests/Makefile.am
+++ b/src/lib/bench/tests/Makefile.am
@@ -5,6 +5,9 @@ AM_CXXFLAGS = $(B10_CXXFLAGS)
 
 CLEANFILES = *.gcno *.gcda
 
+TESTS_ENVIRONMENT = \
+	$(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
 TESTS =
 if HAVE_GTEST
 TESTS += run_unittests
diff --git a/src/lib/bench/tests/benchmark_unittest.cc b/src/lib/bench/tests/benchmark_unittest.cc
index 5f62aad..1497930 100644
--- a/src/lib/bench/tests/benchmark_unittest.cc
+++ b/src/lib/bench/tests/benchmark_unittest.cc
@@ -53,9 +53,6 @@ public:
     const struct timespec sleep_time_;
     bool setup_completed_;
     bool teardown_completed_;
-private:
-    // silence MSVC warning C4512: assignment operator could not be generated
-    TestBenchMark& operator=(TestBenchMark const&);
 };
 }
 
@@ -63,14 +60,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
@@ -87,9 +84,9 @@ TEST(BenchMarkTest, run) {
     const int sleep_time = 50000; // will sleep for 50ms
     const struct timespec sleep_timespec = { 0, sleep_time * 1000 };
     // we cannot expect particular accuracy on the measured duration, so
-    // we'll include some conservative margin (25%) and perform range
+    // we'll include some conservative margin (50%) and perform range
     // comparison below.
-    const int duration_margin = 12500; // 12.5ms
+    const int duration_margin = 25000; // 25ms
     const int ONE_MILLION = 1000000;
 
     // Prerequisite check: since the tests in this case may depend on subtle
@@ -97,6 +94,8 @@ TEST(BenchMarkTest, run) {
     // where sleeping doesn't work as this test expects.  So we check the
     // conditions before the tests, and if it fails skip the tests at the
     // risk of overlooking possible bugs.
+    // We do this with a tighter margin than the checks themselves
+    const int duration_soft_margin = 12500; // 12.5ms
     struct timeval check_begin, check_end;
     gettimeofday(&check_begin, NULL);
 #ifdef _WIN32
@@ -114,8 +113,8 @@ TEST(BenchMarkTest, run) {
         --check_end.tv_sec;
     }
     if (check_end.tv_sec != 0 ||
-        sleep_time - duration_margin > check_end.tv_usec ||
-        sleep_time + duration_margin < check_end.tv_usec) {
+        sleep_time - duration_soft_margin > check_end.tv_usec ||
+        sleep_time + duration_soft_margin < check_end.tv_usec) {
         cerr << "Prerequisite check failed.  skipping test" << endl;
         return;
     }
diff --git a/src/lib/bench/tests/loadquery_unittest.cc b/src/lib/bench/tests/loadquery_unittest.cc
index c6380c2..93130d2 100644
--- a/src/lib/bench/tests/loadquery_unittest.cc
+++ b/src/lib/bench/tests/loadquery_unittest.cc
@@ -61,8 +61,6 @@ public:
     }
 private:
     stringstream& stream_;
-    // silence MSVC warning C4512: assignment operator could not be generated
-    QueryInserter& operator=(QueryInserter const&);
 };
 
 class QueryChecker {
@@ -105,8 +103,6 @@ private:
     const vector<QueryParam>* expected_;
     vector<QueryParam>::const_iterator iter_;
     const RRClass rrclass_;
-    // silence MSVC warning C4512: assignment operator could not be generated
-    QueryChecker& operator=(QueryChecker const&);
 };
 
 TEST_F(LoadQueryTest, load) {



More information about the bind10-changes mailing list