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
49bbff2c
Commit
49bbff2c
authored
Aug 29, 2016
by
Eric
Committed by
Dominic Hamon
Aug 29, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Supply old `RangePair` and `ArgPair` API for C++03 compatibility. (#278)
* changes * remove other changes * remove unneeded test * cleanup unused include
parent
2e0796e1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
3 deletions
+51
-3
benchmark_api.h
include/benchmark/benchmark_api.h
+27
-1
macros.h
include/benchmark/macros.h
+2
-0
cxx03_test.cc
test/cxx03_test.cc
+12
-1
multiple_ranges_test.cc
test/multiple_ranges_test.cc
+10
-1
No files found.
include/benchmark/benchmark_api.h
View file @
49bbff2c
...
...
@@ -429,11 +429,17 @@ public:
// Range arguments for this run. CHECKs if the argument has been set.
BENCHMARK_ALWAYS_INLINE
int
range
(
std
::
size_t
pos
)
const
{
int
range
(
std
::
size_t
pos
=
0
)
const
{
assert
(
range_
.
size
()
>
pos
);
return
range_
[
pos
];
}
BENCHMARK_DEPRECATED_MSG
(
"use 'range(0)' instead"
)
int
range_x
()
const
{
return
range
(
0
);
}
BENCHMARK_DEPRECATED_MSG
(
"use 'range(1)' instead"
)
int
range_y
()
const
{
return
range
(
1
);
}
BENCHMARK_ALWAYS_INLINE
size_t
iterations
()
const
{
return
total_iterations_
;
}
...
...
@@ -502,11 +508,31 @@ public:
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark
*
Args
(
const
std
::
vector
<
int
>&
args
);
// Equivalent to Args({x, y})
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Args'.
Benchmark
*
ArgPair
(
int
x
,
int
y
)
{
std
::
vector
<
int
>
args
;
args
.
push_back
(
x
);
args
.
push_back
(
y
);
return
Args
(
args
);
}
// Run this benchmark once for a number of values picked from the
// ranges [start..limit]. (starts and limits are always picked.)
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark
*
Ranges
(
const
std
::
vector
<
std
::
pair
<
int
,
int
>
>&
ranges
);
// Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Ranges'.
Benchmark
*
RangePair
(
int
lo1
,
int
hi1
,
int
lo2
,
int
hi2
)
{
std
::
vector
<
std
::
pair
<
int
,
int
>
>
ranges
;
ranges
.
push_back
(
std
::
make_pair
(
lo1
,
hi1
));
ranges
.
push_back
(
std
::
make_pair
(
lo2
,
hi2
));
return
Ranges
(
ranges
);
}
// Pass this benchmark object to *func, which can customize
// the benchmark by calling various methods like Arg, Args,
// Threads, etc.
...
...
include/benchmark/macros.h
View file @
49bbff2c
...
...
@@ -53,8 +53,10 @@
#if defined(__GNUC__)
# define BENCHMARK_BUILTIN_EXPECT(x, y) __builtin_expect(x, y)
# define BENCHMARK_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#else
# define BENCHMARK_BUILTIN_EXPECT(x, y) x
# define BENCHMARK_DEPRECATED_MSG(msg)
#endif
#if defined(__GNUC__) && !defined(__clang__)
...
...
test/cxx03_test.cc
View file @
49bbff2c
#undef NDEBUG
#include <cstddef>
#include <cassert>
#include "benchmark/benchmark.h"
...
...
@@ -15,6 +16,16 @@ void BM_empty(benchmark::State& state) {
}
BENCHMARK
(
BM_empty
);
// The new C++11 interface for args/ranges requires initializer list support.
// Therefore we provide the old interface to support C++03.
void
BM_old_arg_range_interface
(
benchmark
::
State
&
state
)
{
assert
((
state
.
range
(
0
)
==
1
&&
state
.
range
(
1
)
==
2
)
||
(
state
.
range
(
0
)
==
5
&&
state
.
range
(
1
)
==
6
));
while
(
state
.
KeepRunning
())
{
}
}
BENCHMARK
(
BM_old_arg_range_interface
)
->
ArgPair
(
1
,
2
)
->
RangePair
(
5
,
5
,
6
,
6
);
template
<
class
T
,
class
U
>
void
BM_template2
(
benchmark
::
State
&
state
)
{
BM_empty
(
state
);
...
...
test/multiple_ranges_test.cc
View file @
49bbff2c
...
...
@@ -41,7 +41,16 @@ BENCHMARK_DEFINE_F(MultipleRangesFixture, Empty)(benchmark::State& state) {
}
}
BENCHMARK_REGISTER_F
(
MultipleRangesFixture
,
Empty
)
->
RangeMultiplier
(
2
)
->
Ranges
({{
1
,
2
},
{
3
,
7
},
{
5
,
15
}})
->
Args
({
7
,
6
,
3
});
BENCHMARK_REGISTER_F
(
MultipleRangesFixture
,
Empty
)
->
RangeMultiplier
(
2
)
->
Ranges
({{
1
,
2
},
{
3
,
7
},
{
5
,
15
}})
->
Args
({
7
,
6
,
3
});
void
BM_CheckDefaultArgument
(
benchmark
::
State
&
state
)
{
// Test that the 'range()' without an argument is the same as 'range(0)'.
assert
(
state
.
range
()
==
state
.
range
(
0
));
assert
(
state
.
range
()
!=
state
.
range
(
1
));
while
(
state
.
KeepRunning
())
{}
}
BENCHMARK
(
BM_CheckDefaultArgument
)
->
Ranges
({{
1
,
5
},
{
6
,
10
}});
static
void
BM_MultipleRanges
(
benchmark
::
State
&
st
)
{
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