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
31e71be7
Commit
31e71be7
authored
Feb 16, 2016
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #181 from google/map_test
Pass const state to Fixture::SetUp. Add map_test.
parents
7fd3fa8e
53068f97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
22 deletions
+81
-22
benchmark_api.h
include/benchmark/benchmark_api.h
+2
-2
CMakeLists.txt
test/CMakeLists.txt
+3
-0
fixture_test.cc
test/fixture_test.cc
+19
-20
map_test.cc
test/map_test.cc
+57
-0
No files found.
include/benchmark/benchmark_api.h
View file @
31e71be7
...
@@ -489,12 +489,12 @@ public:
...
@@ -489,12 +489,12 @@ public:
Fixture
()
:
internal
::
Benchmark
(
""
)
{}
Fixture
()
:
internal
::
Benchmark
(
""
)
{}
virtual
void
Run
(
State
&
st
)
{
virtual
void
Run
(
State
&
st
)
{
this
->
SetUp
();
this
->
SetUp
(
st
);
this
->
BenchmarkCase
(
st
);
this
->
BenchmarkCase
(
st
);
this
->
TearDown
();
this
->
TearDown
();
}
}
virtual
void
SetUp
()
{}
virtual
void
SetUp
(
const
State
&
)
{}
virtual
void
TearDown
()
{}
virtual
void
TearDown
()
{}
protected
:
protected
:
...
...
test/CMakeLists.txt
View file @
31e71be7
...
@@ -39,6 +39,9 @@ add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
...
@@ -39,6 +39,9 @@ add_test(basic_benchmark basic_test --benchmark_min_time=0.01)
compile_benchmark_test
(
fixture_test
)
compile_benchmark_test
(
fixture_test
)
add_test
(
fixture_test fixture_test --benchmark_min_time=0.01
)
add_test
(
fixture_test fixture_test --benchmark_min_time=0.01
)
compile_benchmark_test
(
map_test
)
add_test
(
map_test map_test --benchmark_min_time=0.01
)
compile_benchmark_test
(
cxx03_test
)
compile_benchmark_test
(
cxx03_test
)
set_target_properties
(
cxx03_test
set_target_properties
(
cxx03_test
PROPERTIES COMPILE_FLAGS
"
${
CXX03_FLAGS
}
"
)
PROPERTIES COMPILE_FLAGS
"
${
CXX03_FLAGS
}
"
)
...
...
test/fixture_test.cc
View file @
31e71be7
...
@@ -2,33 +2,33 @@
...
@@ -2,33 +2,33 @@
#include "benchmark/benchmark.h"
#include "benchmark/benchmark.h"
#include <cassert>
#include <cassert>
#include <memory>
class
MyFixture
:
public
::
benchmark
::
Fixture
class
MyFixture
:
public
::
benchmark
::
Fixture
{
{
public
:
public
:
void
SetUp
(
const
::
benchmark
::
State
&
)
{
void
SetUp
()
{
assert
(
data
.
get
()
==
nullptr
);
data
=
new
int
(
42
);
data
.
reset
(
new
int
(
42
)
);
}
}
void
TearDown
()
{
void
TearDown
()
{
assert
(
data
!=
nullptr
);
assert
(
data
.
get
()
!=
nullptr
);
delete
data
;
data
.
release
();
data
=
nullptr
;
}
}
~
MyFixture
()
{
~
MyFixture
()
{
assert
(
data
==
nullptr
);
assert
(
data
==
nullptr
);
}
}
int
*
data
;
std
::
unique_ptr
<
int
>
data
;
};
};
BENCHMARK_F
(
MyFixture
,
Foo
)(
benchmark
::
State
&
st
)
{
BENCHMARK_F
(
MyFixture
,
Foo
)(
benchmark
::
State
&
st
)
{
assert
(
data
!=
nullptr
);
assert
(
data
.
get
()
!=
nullptr
);
assert
(
*
data
==
42
);
assert
(
*
data
==
42
);
while
(
st
.
KeepRunning
())
{
while
(
st
.
KeepRunning
())
{
}
}
}
}
BENCHMARK_DEFINE_F
(
MyFixture
,
Bar
)(
benchmark
::
State
&
st
)
{
BENCHMARK_DEFINE_F
(
MyFixture
,
Bar
)(
benchmark
::
State
&
st
)
{
...
@@ -38,5 +38,4 @@ BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) {
...
@@ -38,5 +38,4 @@ BENCHMARK_DEFINE_F(MyFixture, Bar)(benchmark::State& st) {
}
}
BENCHMARK_REGISTER_F
(
MyFixture
,
Bar
)
->
Arg
(
42
);
BENCHMARK_REGISTER_F
(
MyFixture
,
Bar
)
->
Arg
(
42
);
BENCHMARK_MAIN
()
BENCHMARK_MAIN
()
test/map_test.cc
0 → 100644
View file @
31e71be7
#include "benchmark/benchmark.h"
#include <map>
namespace
{
std
::
map
<
int
,
int
>
ConstructRandomMap
(
int
size
)
{
std
::
map
<
int
,
int
>
m
;
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
m
.
insert
(
std
::
make_pair
(
rand
()
%
size
,
rand
()
%
size
));
}
return
m
;
}
}
// namespace
// Basic version.
static
void
BM_MapLookup
(
benchmark
::
State
&
state
)
{
const
int
size
=
state
.
range_x
();
while
(
state
.
KeepRunning
())
{
state
.
PauseTiming
();
std
::
map
<
int
,
int
>
m
=
ConstructRandomMap
(
size
);
state
.
ResumeTiming
();
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
benchmark
::
DoNotOptimize
(
m
.
find
(
rand
()
%
size
));
}
}
state
.
SetItemsProcessed
(
state
.
iterations
()
*
size
);
}
BENCHMARK
(
BM_MapLookup
)
->
Range
(
1
<<
3
,
1
<<
12
);
// Using fixtures.
class
MapFixture
:
public
::
benchmark
::
Fixture
{
public
:
void
SetUp
(
const
::
benchmark
::
State
&
st
)
{
m
=
ConstructRandomMap
(
st
.
range_x
());
}
void
TearDown
()
{
m
.
clear
();
}
std
::
map
<
int
,
int
>
m
;
};
BENCHMARK_DEFINE_F
(
MapFixture
,
Lookup
)(
benchmark
::
State
&
state
)
{
const
int
size
=
state
.
range_x
();
while
(
state
.
KeepRunning
())
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
{
benchmark
::
DoNotOptimize
(
m
.
find
(
rand
()
%
size
));
}
}
state
.
SetItemsProcessed
(
state
.
iterations
()
*
size
);
}
BENCHMARK_REGISTER_F
(
MapFixture
,
Lookup
)
->
Range
(
1
<<
3
,
1
<<
12
);
BENCHMARK_MAIN
()
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