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
9341d705
Commit
9341d705
authored
May 24, 2016
by
Eric Fiselier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change --benchmark_list_tests to respect the benchmark filter.
This behavior mirrors how GTest handles these two flags.
parent
e0de8171
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
39 deletions
+46
-39
benchmark_api.h
include/benchmark/benchmark_api.h
+6
-3
benchmark.cc
src/benchmark.cc
+18
-29
CMakeLists.txt
test/CMakeLists.txt
+1
-0
filter_test.cc
test/filter_test.cc
+21
-7
No files found.
include/benchmark/benchmark_api.h
View file @
9341d705
...
@@ -160,11 +160,14 @@ class BenchmarkReporter;
...
@@ -160,11 +160,14 @@ class BenchmarkReporter;
void
Initialize
(
int
*
argc
,
char
**
argv
);
void
Initialize
(
int
*
argc
,
char
**
argv
);
// Run all benchmarks which match the specified --benchmark_filter flag.
// Generate a list of benchmarks matching the specified --benchmark_filter flag
// and if --benchmark_list_tests is specified return after printing the name
// of each matching benchmark. Otherwise run each matching benchmark and
// report the results.
//
// The second overload reports the results using the specified 'reporter'.
// The second overload reports the results using the specified 'reporter'.
//
//
// RETURNS: The number of benchmarks run, not including repetitions. If
// RETURNS: The number of matching benchmarks.
// '--benchmark_list_tests' is specified '0' is returned.
size_t
RunSpecifiedBenchmarks
();
size_t
RunSpecifiedBenchmarks
();
size_t
RunSpecifiedBenchmarks
(
BenchmarkReporter
*
reporter
);
size_t
RunSpecifiedBenchmarks
(
BenchmarkReporter
*
reporter
);
...
...
src/benchmark.cc
View file @
9341d705
...
@@ -853,24 +853,9 @@ void State::SetLabel(const char* label) {
...
@@ -853,24 +853,9 @@ void State::SetLabel(const char* label) {
namespace
internal
{
namespace
internal
{
namespace
{
namespace
{
void
PrintBenchmarkList
()
{
void
RunMatchingBenchmarks
(
const
std
::
vector
<
Benchmark
::
Instance
>&
benchmarks
,
std
::
vector
<
Benchmark
::
Instance
>
benchmarks
;
BenchmarkReporter
*
reporter
)
{
auto
families
=
BenchmarkFamilies
::
GetInstance
();
if
(
!
families
->
FindBenchmarks
(
"."
,
&
benchmarks
))
return
;
for
(
const
internal
::
Benchmark
::
Instance
&
benchmark
:
benchmarks
)
{
std
::
cout
<<
benchmark
.
name
<<
"
\n
"
;
}
}
size_t
RunMatchingBenchmarks
(
const
std
::
string
&
spec
,
BenchmarkReporter
*
reporter
)
{
CHECK
(
reporter
!=
nullptr
);
CHECK
(
reporter
!=
nullptr
);
CHECK
(
!
spec
.
empty
());
std
::
vector
<
Benchmark
::
Instance
>
benchmarks
;
auto
families
=
BenchmarkFamilies
::
GetInstance
();
if
(
!
families
->
FindBenchmarks
(
spec
,
&
benchmarks
))
return
0
;
// Determine the width of the name field using a minimum width of 10.
// Determine the width of the name field using a minimum width of 10.
size_t
name_field_width
=
10
;
size_t
name_field_width
=
10
;
...
@@ -894,7 +879,6 @@ size_t RunMatchingBenchmarks(const std::string& spec,
...
@@ -894,7 +879,6 @@ size_t RunMatchingBenchmarks(const std::string& spec,
RunBenchmark
(
benchmark
,
reporter
);
RunBenchmark
(
benchmark
,
reporter
);
}
}
}
}
return
benchmarks
.
size
();
}
}
std
::
unique_ptr
<
BenchmarkReporter
>
GetDefaultReporter
()
{
std
::
unique_ptr
<
BenchmarkReporter
>
GetDefaultReporter
()
{
...
@@ -919,22 +903,27 @@ size_t RunSpecifiedBenchmarks() {
...
@@ -919,22 +903,27 @@ size_t RunSpecifiedBenchmarks() {
}
}
size_t
RunSpecifiedBenchmarks
(
BenchmarkReporter
*
reporter
)
{
size_t
RunSpecifiedBenchmarks
(
BenchmarkReporter
*
reporter
)
{
if
(
FLAGS_benchmark_list_tests
)
{
internal
::
PrintBenchmarkList
();
return
0
;
}
std
::
string
spec
=
FLAGS_benchmark_filter
;
std
::
string
spec
=
FLAGS_benchmark_filter
;
if
(
spec
.
empty
()
||
spec
==
"all"
)
if
(
spec
.
empty
()
||
spec
==
"all"
)
spec
=
"."
;
// Regexp that matches all benchmarks
spec
=
"."
;
// Regexp that matches all benchmarks
std
::
unique_ptr
<
BenchmarkReporter
>
default_reporter
;
std
::
vector
<
internal
::
Benchmark
::
Instance
>
benchmarks
;
if
(
!
reporter
)
{
auto
families
=
internal
::
BenchmarkFamilies
::
GetInstance
();
default_reporter
=
internal
::
GetDefaultReporter
();
if
(
!
families
->
FindBenchmarks
(
spec
,
&
benchmarks
))
return
0
;
reporter
=
default_reporter
.
get
();
if
(
FLAGS_benchmark_list_tests
)
{
for
(
auto
const
&
benchmark
:
benchmarks
)
std
::
cout
<<
benchmark
.
name
<<
"
\n
"
;
}
else
{
std
::
unique_ptr
<
BenchmarkReporter
>
default_reporter
;
if
(
!
reporter
)
{
default_reporter
=
internal
::
GetDefaultReporter
();
reporter
=
default_reporter
.
get
();
}
internal
::
RunMatchingBenchmarks
(
benchmarks
,
reporter
);
reporter
->
Finalize
();
}
}
size_t
num_run
=
internal
::
RunMatchingBenchmarks
(
spec
,
reporter
);
return
benchmarks
.
size
();
reporter
->
Finalize
();
return
num_run
;
}
}
namespace
internal
{
namespace
internal
{
...
...
test/CMakeLists.txt
View file @
9341d705
...
@@ -14,6 +14,7 @@ add_test(benchmark benchmark_test --benchmark_min_time=0.01)
...
@@ -14,6 +14,7 @@ add_test(benchmark benchmark_test --benchmark_min_time=0.01)
compile_benchmark_test
(
filter_test
)
compile_benchmark_test
(
filter_test
)
macro
(
add_filter_test name filter expect
)
macro
(
add_filter_test name filter expect
)
add_test
(
${
name
}
filter_test --benchmark_min_time=0.01 --benchmark_filter=
${
filter
}
${
expect
}
)
add_test
(
${
name
}
filter_test --benchmark_min_time=0.01 --benchmark_filter=
${
filter
}
${
expect
}
)
add_test
(
${
name
}
_list_only filter_test --benchmark_list_tests --benchmark_filter=
${
filter
}
${
expect
}
)
endmacro
(
add_filter_test
)
endmacro
(
add_filter_test
)
add_filter_test
(
filter_simple
"Foo"
3
)
add_filter_test
(
filter_simple
"Foo"
3
)
...
...
test/filter_test.cc
View file @
9341d705
...
@@ -68,7 +68,11 @@ BENCHMARK(BM_FooBa);
...
@@ -68,7 +68,11 @@ BENCHMARK(BM_FooBa);
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
**
argv
)
{
bool
list_only
=
false
;
for
(
int
i
=
0
;
i
<
argc
;
++
i
)
list_only
|=
std
::
string
(
argv
[
i
]).
find
(
"--benchmark_list_tests"
)
!=
std
::
string
::
npos
;
benchmark
::
Initialize
(
&
argc
,
argv
);
benchmark
::
Initialize
(
&
argc
,
argv
);
TestReporter
test_reporter
;
TestReporter
test_reporter
;
...
@@ -77,15 +81,25 @@ int main(int argc, char* argv[]) {
...
@@ -77,15 +81,25 @@ int main(int argc, char* argv[]) {
if
(
argc
==
2
)
{
if
(
argc
==
2
)
{
// Make sure we ran all of the tests
// Make sure we ran all of the tests
std
::
stringstream
ss
(
argv
[
1
]);
std
::
stringstream
ss
(
argv
[
1
]);
size_t
expected
;
size_t
expected
_return
;
ss
>>
expected
;
ss
>>
expected
_return
;
const
size_t
count
=
test_reporter
.
GetCount
();
if
(
returned_count
!=
expected_return
)
{
if
(
count
!=
expected
||
returned_count
!=
expected
)
{
std
::
cerr
<<
"ERROR: Expected "
<<
expected_return
std
::
cerr
<<
"ERROR: Expected "
<<
expected
<<
" tests to be run but returned_count = "
<<
" tests to match the filter but returned_count = "
<<
returned_count
<<
" and reporter_count = "
<<
count
<<
std
::
endl
;
<<
returned_count
<<
std
::
endl
;
return
-
1
;
}
const
size_t
expected_reports
=
list_only
?
0
:
expected_return
;
const
size_t
reports_count
=
test_reporter
.
GetCount
();
if
(
reports_count
!=
expected_reports
)
{
std
::
cerr
<<
"ERROR: Expected "
<<
expected_reports
<<
" tests to be run but reported_count = "
<<
reports_count
<<
std
::
endl
;
return
-
1
;
return
-
1
;
}
}
}
}
return
0
;
return
0
;
}
}
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