mirror of
https://github.com/google/benchmark.git
synced 2025-01-27 20:30:15 +08:00
address review comments
This commit is contained in:
parent
12f4405870
commit
9ed538f511
30
README.md
30
README.md
@ -175,6 +175,36 @@ static void BM_test(benchmark::State& state) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Benchmark Fixtures
|
||||||
|
------------------
|
||||||
|
Fixture tests are created by
|
||||||
|
first defining a type that derives from ::benchmark::Fixture and then
|
||||||
|
creating/registering the tests using the following macros:
|
||||||
|
|
||||||
|
* `BENCHMARK_F(ClassName, Method)`
|
||||||
|
* `BENCHMARK_DEFINE_F(ClassName, Method)`
|
||||||
|
* `BENCHMARK_REGISTER_F(ClassName, Method)`
|
||||||
|
|
||||||
|
For Example:
|
||||||
|
|
||||||
|
```c++
|
||||||
|
class MyFixture : public benchmark::Fixture {};
|
||||||
|
|
||||||
|
BENCHMARK_F(MyFixture, FooTest)(benchmark::State& st) {
|
||||||
|
while (st.KeepRunning()) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCHMARK_DEFINE_F(MyFixture, BarTest)(benchmark::State& st) {
|
||||||
|
while (st.KeepRunning()) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* BarTest is NOT registered */
|
||||||
|
BENCHMARK_REGISTER_F(MyFixture, BarTest)->Threads(2);
|
||||||
|
/* BarTest is now registered */
|
||||||
|
```
|
||||||
|
|
||||||
Output Formats
|
Output Formats
|
||||||
--------------
|
--------------
|
||||||
|
@ -185,6 +185,8 @@ struct EnableIfString<T, typename Voider<typename T::basic_string>::type> {
|
|||||||
|
|
||||||
void UseCharPointer(char const volatile*);
|
void UseCharPointer(char const volatile*);
|
||||||
|
|
||||||
|
// Take ownership of the pointer and register the benchmark. Return the
|
||||||
|
// registered benchmark.
|
||||||
Benchmark* RegisterBenchmarkInternal(Benchmark*);
|
Benchmark* RegisterBenchmarkInternal(Benchmark*);
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
@ -375,9 +377,7 @@ typedef void(Function)(State&);
|
|||||||
// Each method returns "this" so that multiple method calls can
|
// Each method returns "this" so that multiple method calls can
|
||||||
// chained into one expression.
|
// chained into one expression.
|
||||||
class Benchmark {
|
class Benchmark {
|
||||||
public:
|
public:
|
||||||
Benchmark(const char* name);
|
|
||||||
|
|
||||||
virtual ~Benchmark();
|
virtual ~Benchmark();
|
||||||
|
|
||||||
// Note: the following methods all return "this" so that multiple
|
// Note: the following methods all return "this" so that multiple
|
||||||
@ -455,8 +455,9 @@ class Benchmark {
|
|||||||
struct Instance;
|
struct Instance;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Benchmark(Benchmark const&);
|
explicit Benchmark(const char* name);
|
||||||
void SetName(const char* name);
|
Benchmark(Benchmark const&);
|
||||||
|
void SetName(const char* name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class BenchmarkFamilies;
|
friend class BenchmarkFamilies;
|
||||||
@ -480,23 +481,7 @@ private:
|
|||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
// The base class for all fixture tests. Fixture tests are created by
|
// The base class for all fixture tests.
|
||||||
// first defining a type that derives from ::benchmark::Fixture and then
|
|
||||||
// creating/registering the tests using the following macros:
|
|
||||||
//
|
|
||||||
// * BENCHMARK_F(ClassName, Method)
|
|
||||||
// * BENCHMARK_DEFINE_F(ClassName, Method)
|
|
||||||
// * BENCHMARK_REGISTER_F(ClassName, Method)
|
|
||||||
//
|
|
||||||
// For Example:
|
|
||||||
//
|
|
||||||
// class MyFixture : public benchmark::Fixture {};
|
|
||||||
//
|
|
||||||
// BENCHMARK_F(MyFixture, FooTest)(benchmark::State& st) {
|
|
||||||
// while (st.KeepRunning()) {
|
|
||||||
// ...
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
class Fixture: public internal::Benchmark {
|
class Fixture: public internal::Benchmark {
|
||||||
public:
|
public:
|
||||||
Fixture() : internal::Benchmark("") {}
|
Fixture() : internal::Benchmark("") {}
|
||||||
@ -580,44 +565,29 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
|
#define BENCHMARK_PRIVATE_DECLARE_F(BaseClass, Method) \
|
||||||
class BaseClass##_##Method##_Test : public BaseClass { \
|
class BaseClass##_##Method##_Benchmark : public BaseClass { \
|
||||||
public:\
|
public:\
|
||||||
BaseClass##_##Method##_Test() : BaseClass() {this->SetName(#BaseClass "/" #Method);} \
|
BaseClass##_##Method##_Benchmark() : BaseClass() {this->SetName(#BaseClass "/" #Method);} \
|
||||||
protected: \
|
protected: \
|
||||||
virtual void TestCase(::benchmark::State&); \
|
virtual void TestCase(::benchmark::State&); \
|
||||||
};
|
};
|
||||||
|
|
||||||
// The BENCHMARK_DEFINE_F(...) and BENCHMARK_REGISTER_F(...) macros are used
|
|
||||||
// to define and register new fixture benchmarks in two steps.
|
|
||||||
// Example:
|
|
||||||
//
|
|
||||||
// class MyFixture : public ::benchmark::Fixture {};
|
|
||||||
//
|
|
||||||
// BENCHMARK_DEFINE_F(MyFixture, Method)(benchmark::State& st) {
|
|
||||||
// while(st.KeepRunning()) {
|
|
||||||
// ...
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// /* the test is not registered. */
|
|
||||||
// BENCHMARK_REGISTER_F(MyFixture, Method)->Arg(42);
|
|
||||||
// /* the test is now registered */
|
|
||||||
#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##_Test::TestCase
|
void BaseClass##_##Method##_Benchmark::TestCase
|
||||||
|
|
||||||
#define BENCHMARK_REGISTER_F(BaseClass, Method) \
|
#define BENCHMARK_REGISTER_F(BaseClass, Method) \
|
||||||
BENCHMARK_PRIVATE_REGISTER_F(BaseClass##_##Method##_Test)
|
BENCHMARK_PRIVATE_REGISTER_F(BaseClass##_##Method##_Benchmark)
|
||||||
|
|
||||||
#define BENCHMARK_PRIVATE_REGISTER_F(TestName) \
|
#define BENCHMARK_PRIVATE_REGISTER_F(TestName) \
|
||||||
BENCHMARK_PRIVATE_DECLARE(TestName) = \
|
BENCHMARK_PRIVATE_DECLARE(TestName) = \
|
||||||
(::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
|
(::benchmark::internal::RegisterBenchmarkInternal(new TestName()))
|
||||||
|
|
||||||
// This function will define and register a benchmark within a fixture class.
|
// This macro will define and register a benchmark within a fixture class.
|
||||||
// See Fixture for more information.
|
|
||||||
#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##_Test::TestCase
|
void BaseClass##_##Method##_Benchmark::TestCase
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -289,7 +289,7 @@ class BenchmarkFamilies {
|
|||||||
|
|
||||||
class BenchmarkImp {
|
class BenchmarkImp {
|
||||||
public:
|
public:
|
||||||
BenchmarkImp(const char* name);
|
explicit BenchmarkImp(const char* name);
|
||||||
~BenchmarkImp();
|
~BenchmarkImp();
|
||||||
|
|
||||||
void Arg(int x);
|
void Arg(int x);
|
||||||
|
Loading…
Reference in New Issue
Block a user