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
53aca9bc
Commit
53aca9bc
authored
Feb 24, 2016
by
Mohamed Amin JABRI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass const State to Fixture::TearDown. Fix memory leak in fixture_test
parent
c5b80ff1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
9 deletions
+20
-9
benchmark_api.h
include/benchmark/benchmark_api.h
+2
-2
fixture_test.cc
test/fixture_test.cc
+17
-6
map_test.cc
test/map_test.cc
+1
-1
No files found.
include/benchmark/benchmark_api.h
View file @
53aca9bc
...
...
@@ -491,11 +491,11 @@ public:
virtual
void
Run
(
State
&
st
)
{
this
->
SetUp
(
st
);
this
->
BenchmarkCase
(
st
);
this
->
TearDown
();
this
->
TearDown
(
st
);
}
virtual
void
SetUp
(
const
State
&
)
{}
virtual
void
TearDown
()
{}
virtual
void
TearDown
(
const
State
&
)
{}
protected
:
virtual
void
BenchmarkCase
(
State
&
)
=
0
;
...
...
test/fixture_test.cc
View file @
53aca9bc
...
...
@@ -6,14 +6,18 @@
class
MyFixture
:
public
::
benchmark
::
Fixture
{
public
:
void
SetUp
(
const
::
benchmark
::
State
&
)
{
assert
(
data
.
get
()
==
nullptr
);
data
.
reset
(
new
int
(
42
));
void
SetUp
(
const
::
benchmark
::
State
&
state
)
{
if
(
state
.
thread_index
==
0
)
{
assert
(
data
.
get
()
==
nullptr
);
data
.
reset
(
new
int
(
42
));
}
}
void
TearDown
()
{
assert
(
data
.
get
()
!=
nullptr
);
data
.
release
();
void
TearDown
(
const
::
benchmark
::
State
&
state
)
{
if
(
state
.
thread_index
==
0
)
{
assert
(
data
.
get
()
!=
nullptr
);
data
.
reset
();
}
}
~
MyFixture
()
{
...
...
@@ -32,10 +36,17 @@ BENCHMARK_F(MyFixture, Foo)(benchmark::State& st) {
}
BENCHMARK_DEFINE_F
(
MyFixture
,
Bar
)(
benchmark
::
State
&
st
)
{
if
(
st
.
thread_index
==
0
)
{
assert
(
data
.
get
()
!=
nullptr
);
assert
(
*
data
==
42
);
}
while
(
st
.
KeepRunning
())
{
assert
(
data
.
get
()
!=
nullptr
);
assert
(
*
data
==
42
);
}
st
.
SetItemsProcessed
(
st
.
range_x
());
}
BENCHMARK_REGISTER_F
(
MyFixture
,
Bar
)
->
Arg
(
42
);
BENCHMARK_REGISTER_F
(
MyFixture
,
Bar
)
->
Arg
(
42
)
->
ThreadPerCpu
();
BENCHMARK_MAIN
()
test/map_test.cc
View file @
53aca9bc
...
...
@@ -36,7 +36,7 @@ class MapFixture : public ::benchmark::Fixture {
m
=
ConstructRandomMap
(
st
.
range_x
());
}
void
TearDown
()
{
void
TearDown
(
const
::
benchmark
::
State
&
)
{
m
.
clear
();
}
...
...
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