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
8e08aa75
Commit
8e08aa75
authored
Oct 26, 2016
by
Dominic Hamon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mkurdej-arg-names'
parents
44c25c89
3f23832a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
4 deletions
+80
-4
benchmark_api.h
include/benchmark/benchmark_api.h
+9
-2
benchmark_register.cc
src/benchmark_register.cc
+29
-1
string_util.cc
src/string_util.cc
+1
-1
reporter_output_test.cc
test/reporter_output_test.cc
+41
-0
No files found.
include/benchmark/benchmark_api.h
View file @
8e08aa75
...
...
@@ -510,6 +510,13 @@ class Benchmark {
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark
*
Ranges
(
const
std
::
vector
<
std
::
pair
<
int
,
int
>
>&
ranges
);
// Equivalent to ArgNames({name})
Benchmark
*
ArgName
(
const
std
::
string
&
name
);
// Set the argument names to display in the benchmark name. If not called,
// only argument values will be shown.
Benchmark
*
ArgNames
(
const
std
::
vector
<
std
::
string
>&
names
);
// Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Ranges'.
...
...
@@ -526,8 +533,7 @@ class Benchmark {
Benchmark
*
Apply
(
void
(
*
func
)(
Benchmark
*
benchmark
));
// Set the range multiplier for non-dense range. If not called, the range
// multiplier
// kRangeMultiplier will be used.
// multiplier kRangeMultiplier will be used.
Benchmark
*
RangeMultiplier
(
int
multiplier
);
// Set the minimum amount of time to use when running this benchmark. This
...
...
@@ -618,6 +624,7 @@ class Benchmark {
std
::
string
name_
;
ReportMode
report_mode_
;
std
::
vector
<
std
::
string
>
arg_names_
;
// Args for all benchmark runs
std
::
vector
<
std
::
vector
<
int
>
>
args_
;
// Args for all benchmark runs
TimeUnit
time_unit_
;
int
range_multiplier_
;
...
...
src/benchmark_register.cc
View file @
8e08aa75
...
...
@@ -151,8 +151,20 @@ bool BenchmarkFamilies::FindBenchmarks(
instance
.
threads
=
num_threads
;
// Add arguments to instance name
size_t
arg_i
=
0
;
for
(
auto
const
&
arg
:
args
)
{
instance
.
name
+=
"/"
;
if
(
arg_i
<
family
->
arg_names_
.
size
())
{
const
auto
&
arg_name
=
family
->
arg_names_
[
arg_i
];
if
(
!
arg_name
.
empty
())
{
instance
.
name
+=
StringPrintF
(
"%s:"
,
family
->
arg_names_
[
arg_i
].
c_str
());
}
}
AppendHumanReadable
(
arg
,
&
instance
.
name
);
++
arg_i
;
}
if
(
!
IsZero
(
family
->
min_time_
))
{
...
...
@@ -293,6 +305,18 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
return
this
;
}
Benchmark
*
Benchmark
::
ArgName
(
const
std
::
string
&
name
)
{
CHECK
(
ArgsCnt
()
==
-
1
||
ArgsCnt
()
==
1
);
arg_names_
=
{
name
};
return
this
;
}
Benchmark
*
Benchmark
::
ArgNames
(
const
std
::
vector
<
std
::
string
>&
names
)
{
CHECK
(
ArgsCnt
()
==
-
1
||
ArgsCnt
()
==
static_cast
<
int
>
(
names
.
size
()));
arg_names_
=
names
;
return
this
;
}
Benchmark
*
Benchmark
::
DenseRange
(
int
start
,
int
limit
,
int
step
)
{
CHECK
(
ArgsCnt
()
==
-
1
||
ArgsCnt
()
==
1
);
CHECK_GE
(
start
,
0
);
...
...
@@ -398,7 +422,11 @@ Benchmark* Benchmark::ThreadPerCpu() {
void
Benchmark
::
SetName
(
const
char
*
name
)
{
name_
=
name
;
}
int
Benchmark
::
ArgsCnt
()
const
{
return
args_
.
empty
()
?
-
1
:
static_cast
<
int
>
(
args_
.
front
().
size
());
if
(
args_
.
empty
())
{
if
(
arg_names_
.
empty
())
return
-
1
;
return
static_cast
<
int
>
(
arg_names_
.
size
());
}
return
static_cast
<
int
>
(
args_
.
front
().
size
());
}
//=============================================================================//
...
...
src/string_util.cc
View file @
8e08aa75
...
...
@@ -107,7 +107,7 @@ std::string ToBinaryStringFullySpecified(double value, double threshold,
void
AppendHumanReadable
(
int
n
,
std
::
string
*
str
)
{
std
::
stringstream
ss
;
// Round down to the nearest SI prefix.
ss
<<
"/"
<<
ToBinaryStringFullySpecified
(
n
,
1.0
,
0
);
ss
<<
ToBinaryStringFullySpecified
(
n
,
1.0
,
0
);
*
str
+=
ss
.
str
();
}
...
...
test/reporter_output_test.cc
View file @
8e08aa75
...
...
@@ -52,6 +52,47 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_error\",$"},
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_error
\"
,,,,,,,,true,
\"
message
\"
$"
}});
// ========================================================================= //
// ------------------------ Testing No Arg Name Output -----------------------
// //
// ========================================================================= //
void
BM_no_arg_name
(
benchmark
::
State
&
state
)
{
while
(
state
.
KeepRunning
())
{
}
}
BENCHMARK
(
BM_no_arg_name
)
->
Arg
(
3
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_no_arg_name/3 %console_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_no_arg_name/3
\"
,$"
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_no_arg_name/3
\"
,%csv_report$"
}});
// ========================================================================= //
// ------------------------ Testing Arg Name Output ----------------------- //
// ========================================================================= //
void
BM_arg_name
(
benchmark
::
State
&
state
)
{
while
(
state
.
KeepRunning
())
{
}
}
BENCHMARK
(
BM_arg_name
)
->
ArgName
(
"first"
)
->
Arg
(
3
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_arg_name/first:3 %console_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_arg_name/first:3
\"
,$"
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_arg_name/first:3
\"
,%csv_report$"
}});
// ========================================================================= //
// ------------------------ Testing Arg Names Output ----------------------- //
// ========================================================================= //
void
BM_arg_names
(
benchmark
::
State
&
state
)
{
while
(
state
.
KeepRunning
())
{
}
}
BENCHMARK
(
BM_arg_names
)
->
Args
({
2
,
5
,
4
})
->
ArgNames
({
"first"
,
""
,
"third"
});
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_arg_names/first:2/5/third:4 %console_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_arg_names/first:2/5/third:4
\"
,$"
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_arg_names/first:2/5/third:4
\"
,%csv_report$"
}});
// ========================================================================= //
// ----------------------- Testing Complexity Output ----------------------- //
// ========================================================================= //
...
...
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