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
17e1c405
Commit
17e1c405
authored
Oct 24, 2016
by
Marek Kurdej
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ArgName() and ArgNames() methods to name arguments/ranges.
parent
44c25c89
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
3 deletions
+68
-3
benchmark_api.h
include/benchmark/benchmark_api.h
+9
-2
benchmark_register.cc
src/benchmark_register.cc
+18
-0
string_util.cc
src/string_util.cc
+1
-1
reporter_output_test.cc
test/reporter_output_test.cc
+40
-0
No files found.
include/benchmark/benchmark_api.h
View file @
17e1c405
...
@@ -510,6 +510,13 @@ class Benchmark {
...
@@ -510,6 +510,13 @@ class Benchmark {
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
// REQUIRES: The function passed to the constructor must accept arg1, arg2 ...
Benchmark
*
Ranges
(
const
std
::
vector
<
std
::
pair
<
int
,
int
>
>&
ranges
);
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}}).
// Equivalent to Ranges({{lo1, hi1}, {lo2, hi2}}).
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// NOTE: This is a legacy C++03 interface provided for compatibility only.
// New code should use 'Ranges'.
// New code should use 'Ranges'.
...
@@ -526,8 +533,7 @@ class Benchmark {
...
@@ -526,8 +533,7 @@ class Benchmark {
Benchmark
*
Apply
(
void
(
*
func
)(
Benchmark
*
benchmark
));
Benchmark
*
Apply
(
void
(
*
func
)(
Benchmark
*
benchmark
));
// Set the range multiplier for non-dense range. If not called, the range
// Set the range multiplier for non-dense range. If not called, the range
// multiplier
// multiplier kRangeMultiplier will be used.
// kRangeMultiplier will be used.
Benchmark
*
RangeMultiplier
(
int
multiplier
);
Benchmark
*
RangeMultiplier
(
int
multiplier
);
// Set the minimum amount of time to use when running this benchmark. This
// Set the minimum amount of time to use when running this benchmark. This
...
@@ -618,6 +624,7 @@ class Benchmark {
...
@@ -618,6 +624,7 @@ class Benchmark {
std
::
string
name_
;
std
::
string
name_
;
ReportMode
report_mode_
;
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
std
::
vector
<
std
::
vector
<
int
>
>
args_
;
// Args for all benchmark runs
TimeUnit
time_unit_
;
TimeUnit
time_unit_
;
int
range_multiplier_
;
int
range_multiplier_
;
...
...
src/benchmark_register.cc
View file @
17e1c405
...
@@ -151,8 +151,16 @@ bool BenchmarkFamilies::FindBenchmarks(
...
@@ -151,8 +151,16 @@ bool BenchmarkFamilies::FindBenchmarks(
instance
.
threads
=
num_threads
;
instance
.
threads
=
num_threads
;
// Add arguments to instance name
// Add arguments to instance name
size_t
arg_i
=
0
;
for
(
auto
const
&
arg
:
args
)
{
for
(
auto
const
&
arg
:
args
)
{
if
(
arg_i
<
family
->
arg_names_
.
size
())
{
instance
.
name
+=
StringPrintF
(
"/%s:"
,
family
->
arg_names_
[
arg_i
].
c_str
());
}
else
{
instance
.
name
+=
"/"
;
}
AppendHumanReadable
(
arg
,
&
instance
.
name
);
AppendHumanReadable
(
arg
,
&
instance
.
name
);
++
arg_i
;
}
}
if
(
!
IsZero
(
family
->
min_time_
))
{
if
(
!
IsZero
(
family
->
min_time_
))
{
...
@@ -293,6 +301,16 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
...
@@ -293,6 +301,16 @@ Benchmark* Benchmark::Ranges(const std::vector<std::pair<int, int>>& ranges) {
return
this
;
return
this
;
}
}
Benchmark
*
Benchmark
::
ArgName
(
const
std
::
string
&
name
)
{
arg_names_
=
{
name
};
return
this
;
}
Benchmark
*
Benchmark
::
ArgNames
(
const
std
::
vector
<
std
::
string
>&
names
)
{
arg_names_
=
names
;
return
this
;
}
Benchmark
*
Benchmark
::
DenseRange
(
int
start
,
int
limit
,
int
step
)
{
Benchmark
*
Benchmark
::
DenseRange
(
int
start
,
int
limit
,
int
step
)
{
CHECK
(
ArgsCnt
()
==
-
1
||
ArgsCnt
()
==
1
);
CHECK
(
ArgsCnt
()
==
-
1
||
ArgsCnt
()
==
1
);
CHECK_GE
(
start
,
0
);
CHECK_GE
(
start
,
0
);
...
...
src/string_util.cc
View file @
17e1c405
...
@@ -107,7 +107,7 @@ std::string ToBinaryStringFullySpecified(double value, double threshold,
...
@@ -107,7 +107,7 @@ std::string ToBinaryStringFullySpecified(double value, double threshold,
void
AppendHumanReadable
(
int
n
,
std
::
string
*
str
)
{
void
AppendHumanReadable
(
int
n
,
std
::
string
*
str
)
{
std
::
stringstream
ss
;
std
::
stringstream
ss
;
// Round down to the nearest SI prefix.
// Round down to the nearest SI prefix.
ss
<<
"/"
<<
ToBinaryStringFullySpecified
(
n
,
1.0
,
0
);
ss
<<
ToBinaryStringFullySpecified
(
n
,
1.0
,
0
);
*
str
+=
ss
.
str
();
*
str
+=
ss
.
str
();
}
}
...
...
test/reporter_output_test.cc
View file @
17e1c405
...
@@ -52,6 +52,46 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_error\",$"},
...
@@ -52,6 +52,46 @@ ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_error\",$"},
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_error
\"
,,,,,,,,true,
\"
message
\"
$"
}});
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
)
->
Arg
(
3
)
->
ArgName
(
"first"
);
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
,
4
})
->
ArgNames
({
"first"
,
"second"
});
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_arg_names/first:2/second:4 %console_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_arg_names/first:2/second:4
\"
,$"
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_arg_names/first:2/second:4
\"
,%csv_report$"
}});
// ========================================================================= //
// ----------------------- Testing Complexity Output ----------------------- //
// ----------------------- 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