Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
9ed538f5
Commit
9ed538f5
authored
Apr 06, 2015
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address review comments
parent
12f44058
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
44 deletions
+44
-44
README.md
README.md
+30
-0
benchmark_api.h
include/benchmark/benchmark_api.h
+13
-43
benchmark.cc
src/benchmark.cc
+1
-1
No files found.
README.md
View file @
9ed538f5
...
@@ -175,6 +175,36 @@ static void BM_test(benchmark::State& state) {
...
@@ -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
--------------
--------------
...
...
include/benchmark/benchmark_api.h
View file @
9ed538f5
...
@@ -185,6 +185,8 @@ struct EnableIfString<T, typename Voider<typename T::basic_string>::type> {
...
@@ -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&);
...
@@ -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 {
...
@@ -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:
...
@@ -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:
...
@@ -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
...
...
src/benchmark.cc
View file @
9ed538f5
...
@@ -289,7 +289,7 @@ class BenchmarkFamilies {
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment