2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[master] Revert "[master] Merge branch 'trac1773'"

This was an older version of the branch, and wasn't expected to be a
merge target.  I'll revert it and then merge the right branch.
This commit is contained in:
JINMEI Tatuya
2012-04-04 15:27:21 -07:00
parent d5e250eff9
commit dddc267e55
3 changed files with 26 additions and 32 deletions

View File

@@ -17,7 +17,6 @@
#include <sys/time.h> #include <sys/time.h>
#include <cassert>
#include <iostream> #include <iostream>
#include <ios> #include <ios>
@@ -211,9 +210,9 @@ public:
/// \param target The templated class object that /// \param target The templated class object that
/// implements the code to be benchmarked. /// implements the code to be benchmarked.
BenchMark(const int iterations, T target) : BenchMark(const int iterations, T target) :
iterations_(iterations), sub_iterations_(0) iterations_(iterations), sub_iterations_(0), target_(target)
{ {
initialize(target, true); initialize(true);
} }
/// \brief Constructor for finer-grained control. /// \brief Constructor for finer-grained control.
@@ -231,9 +230,9 @@ public:
/// \param immediate If \c true the benchmark will be performed within /// \param immediate If \c true the benchmark will be performed within
/// the constructor; otherwise it only does initialization. /// the constructor; otherwise it only does initialization.
BenchMark(const int iterations, T& target, const bool immediate) : BenchMark(const int iterations, T& target, const bool immediate) :
iterations_(iterations), sub_iterations_(0), target_(&target) iterations_(iterations), sub_iterations_(0), target_(target)
{ {
initialize(target, immediate); initialize(immediate);
} }
//@} //@}
@@ -242,14 +241,14 @@ public:
/// This method will be called from \c run() before starting the benchmark. /// This method will be called from \c run() before starting the benchmark.
/// By default it's empty, but can be customized via template /// By default it's empty, but can be customized via template
/// specialization. /// specialization.
void setUp(T&) {} void setUp() {}
/// \brief Hook to be called after benchmark. /// \brief Hook to be called after benchmark.
/// ///
/// This method will be called from \c run() when the benchmark completes. /// This method will be called from \c run() when the benchmark completes.
/// By default it's empty, but can be customized via template /// By default it's empty, but can be customized via template
/// specialization. /// specialization.
void tearDown(T&) {} void tearDown() {}
/// \brief Perform benchmark. /// \brief Perform benchmark.
/// ///
@@ -258,8 +257,17 @@ public:
/// of times specified on construction, and records the time on completion. /// of times specified on construction, and records the time on completion.
/// Finally, it calls \c tearDown(). /// Finally, it calls \c tearDown().
void run() { void run() {
assert(target_ != NULL); setUp();
run(*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();
} }
/// \brief Print the benchmark result. /// \brief Print the benchmark result.
@@ -353,23 +361,9 @@ public:
/// performed implicitly. /// performed implicitly.
static const int ITERATION_FAILURE = -1; static const int ITERATION_FAILURE = -1;
private: private:
void run(T& target) { void initialize(const bool immediate) {
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) { if (immediate) {
run(target); run();
printResult(); printResult();
} }
} }
@@ -394,7 +388,7 @@ private:
static const int ONE_MILLION = 1000000; static const int ONE_MILLION = 1000000;
const unsigned int iterations_; const unsigned int iterations_;
unsigned int sub_iterations_; unsigned int sub_iterations_;
T* target_; T& target_;
struct timeval tv_diff_; struct timeval tv_diff_;
}; };

View File

@@ -79,9 +79,9 @@ namespace isc {
namespace bench { namespace bench {
template<> template<>
void void
BenchMark<SetSearchBenchMark>::setUp(SetSearchBenchMark& target) { BenchMark<SetSearchBenchMark>::setUp() {
cout << "Benchmark for searching std::set (size=" cout << "Benchmark for searching std::set (size="
<< target.data_.size() << ")" << endl; << target_.data_.size() << ")" << endl;
} }
} }
} }

View File

@@ -46,14 +46,14 @@ namespace isc {
namespace bench { namespace bench {
template <> template <>
void void
BenchMark<TestBenchMark>::setUp(TestBenchMark& target) { BenchMark<TestBenchMark>::setUp() {
target.setup_completed_ = true; target_.setup_completed_ = true;
}; };
template <> template <>
void void
BenchMark<TestBenchMark>::tearDown(TestBenchMark& target) { BenchMark<TestBenchMark>::tearDown() {
target.teardown_completed_ = true; target_.teardown_completed_ = true;
}; };
// XXX: some compilers cannot find class static constants used in // XXX: some compilers cannot find class static constants used in