Commit 9c25a67c by Eric Fiselier

address more review comments

parent 9ed538f5
...@@ -488,7 +488,7 @@ public: ...@@ -488,7 +488,7 @@ public:
virtual void Run(State& st) { virtual void Run(State& st) {
this->SetUp(); this->SetUp();
this->TestCase(st); this->BenchmarkCase(st);
this->TearDown(); this->TearDown();
} }
...@@ -496,7 +496,7 @@ public: ...@@ -496,7 +496,7 @@ public:
virtual void TearDown() {} virtual void TearDown() {}
protected: protected:
virtual void TestCase(State&) = 0; virtual void BenchmarkCase(State&) = 0;
}; };
} // end namespace benchmark } // end namespace benchmark
...@@ -525,8 +525,9 @@ protected: ...@@ -525,8 +525,9 @@ protected:
BENCHMARK_PRIVATE_NAME(n) BENCHMARK_UNUSED BENCHMARK_PRIVATE_NAME(n) BENCHMARK_UNUSED
#define BENCHMARK(n) \ #define BENCHMARK(n) \
BENCHMARK_PRIVATE_DECLARE(n) = (::benchmark::internal::RegisterBenchmarkInternal( \ BENCHMARK_PRIVATE_DECLARE(n) = \
new ::benchmark::internal::FunctionBenchmark(#n, n))) (::benchmark::internal::RegisterBenchmarkInternal( \
new ::benchmark::internal::FunctionBenchmark(#n, n)))
// Old-style macros // Old-style macros
#define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a)) #define BENCHMARK_WITH_ARG(n, a) BENCHMARK(n)->Arg((a))
...@@ -548,10 +549,11 @@ protected: ...@@ -548,10 +549,11 @@ protected:
(::benchmark::internal::RegisterBenchmarkInternal( \ (::benchmark::internal::RegisterBenchmarkInternal( \
new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>))) new ::benchmark::internal::FunctionBenchmark(#n "<" #a ">", n<a>)))
#define BENCHMARK_TEMPLATE2(n, a, b) \ #define BENCHMARK_TEMPLATE2(n, a, b) \
BENCHMARK_PRIVATE_DECLARE(n) = \ BENCHMARK_PRIVATE_DECLARE(n) = \
(::benchmark::internal::RegisterBenchmarkInternal( \ (::benchmark::internal::RegisterBenchmarkInternal( \
new ::benchmark::internal::FunctionBenchmark(#n "<" #a "," #b ">", n<a, b>))) new ::benchmark::internal::FunctionBenchmark( \
#n "<" #a "," #b ">", n<a, b>)))
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#define BENCHMARK_TEMPLATE(n, ...) \ #define BENCHMARK_TEMPLATE(n, ...) \
...@@ -564,17 +566,18 @@ protected: ...@@ -564,17 +566,18 @@ protected:
#endif #endif
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \ #define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
class BaseClass##_##Method##_Benchmark : public BaseClass { \ class BaseClass##_##Method##_Benchmark : public BaseClass { \
public:\ public: \
BaseClass##_##Method##_Benchmark() : BaseClass() {this->SetName(#BaseClass "/" #Method);} \ BaseClass##_##Method##_Benchmark() : BaseClass() { \
protected: \ this->SetName(#BaseClass "/" #Method);} \
virtual void TestCase(::benchmark::State&); \ protected: \
virtual void BenchmarkCase(::benchmark::State&); \
}; };
#define BENCHMARK_DEFINE_F(BaseClass, Method) \ #define BENCHMARK_DEFINE_F(BaseClass, Method) \
BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \ BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
void BaseClass##_##Method##_Benchmark::TestCase void BaseClass##_##Method##_Benchmark::BenchmarkCase
#define BENCHMARK_REGISTER_F(BaseClass, Method) \ #define BENCHMARK_REGISTER_F(BaseClass, Method) \
BENCHMARK_PRIVATE_REGISTER_F(BaseClass##_##Method##_Benchmark) BENCHMARK_PRIVATE_REGISTER_F(BaseClass##_##Method##_Benchmark)
...@@ -587,7 +590,7 @@ protected: \ ...@@ -587,7 +590,7 @@ protected: \
#define BENCHMARK_F(BaseClass, Method) \ #define BENCHMARK_F(BaseClass, Method) \
BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \ BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
BENCHMARK_REGISTER_F(BaseClass, Method); \ BENCHMARK_REGISTER_F(BaseClass, Method); \
void BaseClass##_##Method##_Benchmark::TestCase void BaseClass##_##Method##_Benchmark::BenchmarkCase
// Helper macro to create a main routine in a test that runs the benchmarks // Helper macro to create a main routine in a test that runs the benchmarks
......
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include <cassert>
class MyFixture : public ::benchmark::Fixture class MyFixture : public ::benchmark::Fixture
{ {
public:
void SetUp() {
data = new int(42);
}
void TearDown() {
assert(data != nullptr);
delete data;
data = nullptr;
}
~MyFixture() {
assert(data == nullptr);
}
int* data;
}; };
BENCHMARK_F(MyFixture, Foo)(benchmark::State& st) { BENCHMARK_F(MyFixture, Foo)(benchmark::State& st) {
assert(data != nullptr);
assert(*data == 42);
while (st.KeepRunning()) { while (st.KeepRunning()) {
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment