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
9c25a67c
Commit
9c25a67c
authored
Apr 06, 2015
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address more review comments
parent
9ed538f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
14 deletions
+37
-14
benchmark_api.h
include/benchmark/benchmark_api.h
+17
-14
fixture_test.cc
test/fixture_test.cc
+20
-0
No files found.
include/benchmark/benchmark_api.h
View file @
9c25a67c
...
@@ -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
->
Test
Case
(
st
);
this
->
Benchmark
Case
(
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
Test
Case
(
State
&
)
=
0
;
virtual
void
Benchmark
Case
(
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::
Test
Case
void BaseClass##_##Method##_Benchmark::
Benchmark
Case
#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::
Test
Case
void BaseClass##_##Method##_Benchmark::
Benchmark
Case
// 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
...
...
test/fixture_test.cc
View file @
9c25a67c
#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
())
{
}
}
}
}
...
...
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