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
72be9523
Commit
72be9523
authored
Sep 03, 2016
by
Ronny
Committed by
Eric
Sep 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Benchmark::ThreadRange() version with increment instead of multiply (#283)
* add additive thread range * add test
parent
60e88c21
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
benchmark_api.h
include/benchmark/benchmark_api.h
+7
-1
benchmark.cc
src/benchmark.cc
+20
-0
benchmark_test.cc
test/benchmark_test.cc
+22
-1
No files found.
include/benchmark/benchmark_api.h
View file @
72be9523
...
...
@@ -595,7 +595,13 @@ public:
// Foo in 4 threads
// Foo in 8 threads
// Foo in 16 threads
Benchmark
*
ThreadRange
(
int
min_threads
,
int
max_threads
);
Benchmark
*
ThreadRange
(
int
min_threads
,
int
max_threads
);
// For each value n in the range, run this benchmark once using n threads.
// min_threads and max_threads are always included in the range.
// stride specifies the increment. E.g. DenseThreadRange(1, 8, 3) starts
// a benchmark with 1, 4, 7 and 8 threads.
Benchmark
*
DenseThreadRange
(
int
min_threads
,
int
max_threads
,
int
stride
=
1
);
// Equivalent to ThreadRange(NumCPUs(), NumCPUs())
Benchmark
*
ThreadPerCpu
();
...
...
src/benchmark.cc
View file @
72be9523
...
...
@@ -293,6 +293,7 @@ public:
void
ComplexityLambda
(
BigOFunc
*
complexity
);
void
Threads
(
int
t
);
void
ThreadRange
(
int
min_threads
,
int
max_threads
);
void
DenseThreadRange
(
int
min_threads
,
int
max_threads
,
int
stride
);
void
ThreadPerCpu
();
void
SetName
(
const
char
*
name
);
...
...
@@ -548,6 +549,18 @@ void BenchmarkImp::ThreadRange(int min_threads, int max_threads) {
AddRange
(
&
thread_counts_
,
min_threads
,
max_threads
,
2
);
}
void
BenchmarkImp
::
DenseThreadRange
(
int
min_threads
,
int
max_threads
,
int
stride
)
{
CHECK_GT
(
min_threads
,
0
);
CHECK_GE
(
max_threads
,
min_threads
);
CHECK_GE
(
stride
,
1
);
for
(
auto
i
=
min_threads
;
i
<
max_threads
;
i
+=
stride
)
{
thread_counts_
.
push_back
(
i
);
}
thread_counts_
.
push_back
(
max_threads
);
}
void
BenchmarkImp
::
ThreadPerCpu
()
{
static
int
num_cpus
=
NumCPUs
();
thread_counts_
.
push_back
(
num_cpus
);
...
...
@@ -580,6 +593,7 @@ void BenchmarkImp::AddRange(std::vector<int>* dst, int lo, int hi, int mult) {
}
}
Benchmark
::
Benchmark
(
const
char
*
name
)
:
imp_
(
new
BenchmarkImp
(
name
))
{
...
...
@@ -687,6 +701,12 @@ Benchmark* Benchmark::ThreadRange(int min_threads, int max_threads) {
return
this
;
}
Benchmark
*
Benchmark
::
DenseThreadRange
(
int
min_threads
,
int
max_threads
,
int
stride
)
{
imp_
->
DenseThreadRange
(
min_threads
,
max_threads
,
stride
);
return
this
;
}
Benchmark
*
Benchmark
::
ThreadPerCpu
()
{
imp_
->
ThreadPerCpu
();
return
this
;
...
...
test/benchmark_test.cc
View file @
72be9523
...
...
@@ -220,5 +220,26 @@ BENCHMARK_CAPTURE(BM_non_template_args, basic_test, 0, 0);
#endif // __cplusplus >= 201103L
BENCHMARK_MAIN
()
static
void
BM_DenseThreadRanges
(
benchmark
::
State
&
st
)
{
switch
(
st
.
range
(
0
))
{
case
1
:
assert
(
st
.
threads
==
1
||
st
.
threads
==
2
||
st
.
threads
==
3
);
break
;
case
2
:
assert
(
st
.
threads
==
1
||
st
.
threads
==
3
||
st
.
threads
==
4
);
break
;
case
3
:
assert
(
st
.
threads
==
5
||
st
.
threads
==
8
||
st
.
threads
==
11
||
st
.
threads
==
14
);
break
;
default:
assert
(
false
&&
"Invalid test case number"
);
}
while
(
st
.
KeepRunning
())
{
}
}
BENCHMARK
(
BM_DenseThreadRanges
)
->
Arg
(
1
)
->
DenseThreadRange
(
1
,
3
);
BENCHMARK
(
BM_DenseThreadRanges
)
->
Arg
(
2
)
->
DenseThreadRange
(
1
,
4
,
2
);
BENCHMARK
(
BM_DenseThreadRanges
)
->
Arg
(
3
)
->
DenseThreadRange
(
5
,
14
,
3
);
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