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
378ed8ff
Unverified
Commit
378ed8ff
authored
Dec 21, 2020
by
feserr
Committed by
GitHub
Dec 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'seconds' time unit (#1076)
Fixes #1075. * Add an option to report in seconds. * Reduce the time of the test. * Add CSV/JSON tests for new time reports.
parent
bf585a27
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
1 deletion
+101
-1
__init__.py
bindings/python/google_benchmark/__init__.py
+2
-0
benchmark.cc
bindings/python/google_benchmark/benchmark.cc
+1
-0
benchmark.h
include/benchmark/benchmark.h
+5
-1
options_test.cc
test/options_test.cc
+1
-0
output_test_helper.cc
test/output_test_helper.cc
+5
-0
reporter_output_test.cc
test/reporter_output_test.cc
+87
-0
No files found.
bindings/python/google_benchmark/__init__.py
View file @
378ed8ff
...
@@ -34,6 +34,7 @@ from google_benchmark._benchmark import (
...
@@ -34,6 +34,7 @@ from google_benchmark._benchmark import (
kNanosecond
,
kNanosecond
,
kMicrosecond
,
kMicrosecond
,
kMillisecond
,
kMillisecond
,
kSecond
,
oNone
,
oNone
,
o1
,
o1
,
oN
,
oN
,
...
@@ -53,6 +54,7 @@ __all__ = [
...
@@ -53,6 +54,7 @@ __all__ = [
"kNanosecond"
,
"kNanosecond"
,
"kMicrosecond"
,
"kMicrosecond"
,
"kMillisecond"
,
"kMillisecond"
,
"kSecond"
,
"oNone"
,
"oNone"
,
"o1"
,
"o1"
,
"oN"
,
"oN"
,
...
...
bindings/python/google_benchmark/benchmark.cc
View file @
378ed8ff
...
@@ -49,6 +49,7 @@ PYBIND11_MODULE(_benchmark, m) {
...
@@ -49,6 +49,7 @@ PYBIND11_MODULE(_benchmark, m) {
.
value
(
"kNanosecond"
,
TimeUnit
::
kNanosecond
)
.
value
(
"kNanosecond"
,
TimeUnit
::
kNanosecond
)
.
value
(
"kMicrosecond"
,
TimeUnit
::
kMicrosecond
)
.
value
(
"kMicrosecond"
,
TimeUnit
::
kMicrosecond
)
.
value
(
"kMillisecond"
,
TimeUnit
::
kMillisecond
)
.
value
(
"kMillisecond"
,
TimeUnit
::
kMillisecond
)
.
value
(
"kSecond"
,
TimeUnit
::
kSecond
)
.
export_values
();
.
export_values
();
using
benchmark
::
BigO
;
using
benchmark
::
BigO
;
...
...
include/benchmark/benchmark.h
View file @
378ed8ff
...
@@ -407,7 +407,7 @@ typedef std::map<std::string, Counter> UserCounters;
...
@@ -407,7 +407,7 @@ typedef std::map<std::string, Counter> UserCounters;
// TimeUnit is passed to a benchmark in order to specify the order of magnitude
// TimeUnit is passed to a benchmark in order to specify the order of magnitude
// for the measured time.
// for the measured time.
enum
TimeUnit
{
kNanosecond
,
kMicrosecond
,
kMillisecond
};
enum
TimeUnit
{
kNanosecond
,
kMicrosecond
,
kMillisecond
,
kSecond
};
// BigO is passed to a benchmark in order to specify the asymptotic
// BigO is passed to a benchmark in order to specify the asymptotic
// computational
// computational
...
@@ -1577,6 +1577,8 @@ class MemoryManager {
...
@@ -1577,6 +1577,8 @@ class MemoryManager {
inline
const
char
*
GetTimeUnitString
(
TimeUnit
unit
)
{
inline
const
char
*
GetTimeUnitString
(
TimeUnit
unit
)
{
switch
(
unit
)
{
switch
(
unit
)
{
case
kSecond
:
return
"s"
;
case
kMillisecond
:
case
kMillisecond
:
return
"ms"
;
return
"ms"
;
case
kMicrosecond
:
case
kMicrosecond
:
...
@@ -1589,6 +1591,8 @@ inline const char* GetTimeUnitString(TimeUnit unit) {
...
@@ -1589,6 +1591,8 @@ inline const char* GetTimeUnitString(TimeUnit unit) {
inline
double
GetTimeUnitMultiplier
(
TimeUnit
unit
)
{
inline
double
GetTimeUnitMultiplier
(
TimeUnit
unit
)
{
switch
(
unit
)
{
switch
(
unit
)
{
case
kSecond
:
return
1
;
case
kMillisecond
:
case
kMillisecond
:
return
1e3
;
return
1e3
;
case
kMicrosecond
:
case
kMicrosecond
:
...
...
test/options_test.cc
View file @
378ed8ff
...
@@ -25,6 +25,7 @@ BENCHMARK(BM_basic)->Arg(42);
...
@@ -25,6 +25,7 @@ BENCHMARK(BM_basic)->Arg(42);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
10
)
->
Unit
(
benchmark
::
kNanosecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
10
)
->
Unit
(
benchmark
::
kNanosecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
100
)
->
Unit
(
benchmark
::
kMicrosecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
100
)
->
Unit
(
benchmark
::
kMicrosecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
1000
)
->
Unit
(
benchmark
::
kMillisecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
1000
)
->
Unit
(
benchmark
::
kMillisecond
);
BENCHMARK
(
BM_basic_slow
)
->
Arg
(
1000
)
->
Unit
(
benchmark
::
kSecond
);
BENCHMARK
(
BM_basic
)
->
Range
(
1
,
8
);
BENCHMARK
(
BM_basic
)
->
Range
(
1
,
8
);
BENCHMARK
(
BM_basic
)
->
RangeMultiplier
(
2
)
->
Range
(
1
,
8
);
BENCHMARK
(
BM_basic
)
->
RangeMultiplier
(
2
)
->
Range
(
1
,
8
);
BENCHMARK
(
BM_basic
)
->
DenseRange
(
10
,
15
);
BENCHMARK
(
BM_basic
)
->
DenseRange
(
10
,
15
);
...
...
test/output_test_helper.cc
View file @
378ed8ff
...
@@ -48,6 +48,9 @@ SubMap& GetSubstitutions() {
...
@@ -48,6 +48,9 @@ SubMap& GetSubstitutions() {
{
" %s "
,
"[ ]+"
},
{
" %s "
,
"[ ]+"
},
{
"%time"
,
"[ ]*"
+
time_re
+
"[ ]+ns"
},
{
"%time"
,
"[ ]*"
+
time_re
+
"[ ]+ns"
},
{
"%console_report"
,
"[ ]*"
+
time_re
+
"[ ]+ns [ ]*"
+
time_re
+
"[ ]+ns [ ]*[0-9]+"
},
{
"%console_report"
,
"[ ]*"
+
time_re
+
"[ ]+ns [ ]*"
+
time_re
+
"[ ]+ns [ ]*[0-9]+"
},
{
"%console_us_report"
,
"[ ]*"
+
time_re
+
"[ ]+us [ ]*"
+
time_re
+
"[ ]+us [ ]*[0-9]+"
},
{
"%console_ms_report"
,
"[ ]*"
+
time_re
+
"[ ]+ms [ ]*"
+
time_re
+
"[ ]+ms [ ]*[0-9]+"
},
{
"%console_s_report"
,
"[ ]*"
+
time_re
+
"[ ]+s [ ]*"
+
time_re
+
"[ ]+s [ ]*[0-9]+"
},
{
"%console_time_only_report"
,
"[ ]*"
+
time_re
+
"[ ]+ns [ ]*"
+
time_re
+
"[ ]+ns"
},
{
"%console_time_only_report"
,
"[ ]*"
+
time_re
+
"[ ]+ns [ ]*"
+
time_re
+
"[ ]+ns"
},
{
"%console_us_report"
,
"[ ]*"
+
time_re
+
"[ ]+us [ ]*"
+
time_re
+
"[ ]+us [ ]*[0-9]+"
},
{
"%console_us_report"
,
"[ ]*"
+
time_re
+
"[ ]+us [ ]*"
+
time_re
+
"[ ]+us [ ]*[0-9]+"
},
{
"%console_us_time_only_report"
,
"[ ]*"
+
time_re
+
"[ ]+us [ ]*"
+
time_re
+
"[ ]+us"
},
{
"%console_us_time_only_report"
,
"[ ]*"
+
time_re
+
"[ ]+us [ ]*"
+
time_re
+
"[ ]+us"
},
...
@@ -56,6 +59,8 @@ SubMap& GetSubstitutions() {
...
@@ -56,6 +59,8 @@ SubMap& GetSubstitutions() {
"items_per_second,label,error_occurred,error_message"
},
"items_per_second,label,error_occurred,error_message"
},
{
"%csv_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",ns,,,,,"
},
{
"%csv_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",ns,,,,,"
},
{
"%csv_us_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",us,,,,,"
},
{
"%csv_us_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",us,,,,,"
},
{
"%csv_ms_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",ms,,,,,"
},
{
"%csv_s_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",s,,,,,"
},
{
"%csv_bytes_report"
,
{
"%csv_bytes_report"
,
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",ns,"
+
safe_dec_re
+
",,,,"
},
"[0-9]+,"
+
safe_dec_re
+
","
+
safe_dec_re
+
",ns,"
+
safe_dec_re
+
",,,,"
},
{
"%csv_items_report"
,
{
"%csv_items_report"
,
...
...
test/reporter_output_test.cc
View file @
378ed8ff
...
@@ -169,6 +169,93 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_label\",%csv_label_report_begin\"some "
...
@@ -169,6 +169,93 @@ ADD_CASES(TC_CSVOut, {{"^\"BM_label\",%csv_label_report_begin\"some "
"label
\"
%csv_label_report_end$"
}});
"label
\"
%csv_label_report_end$"
}});
// ========================================================================= //
// ========================================================================= //
// ------------------------ Testing Time Label Output ---------------------- //
// ========================================================================= //
void
BM_time_label_nanosecond
(
benchmark
::
State
&
state
)
{
for
(
auto
_
:
state
)
{
}
}
BENCHMARK
(
BM_time_label_nanosecond
)
->
Unit
(
benchmark
::
kNanosecond
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_time_label_nanosecond %console_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_time_label_nanosecond
\"
,$"
},
{
"
\"
run_name
\"
:
\"
BM_time_label_nanosecond
\"
,$"
,
MR_Next
},
{
"
\"
run_type
\"
:
\"
iteration
\"
,$"
,
MR_Next
},
{
"
\"
repetitions
\"
: 0,$"
,
MR_Next
},
{
"
\"
repetition_index
\"
: 0,$"
,
MR_Next
},
{
"
\"
threads
\"
: 1,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
cpu_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
time_unit
\"
:
\"
ns
\"
$"
,
MR_Next
},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_time_label_nanosecond
\"
,%csv_report$"
}});
void
BM_time_label_microsecond
(
benchmark
::
State
&
state
)
{
for
(
auto
_
:
state
)
{
}
}
BENCHMARK
(
BM_time_label_microsecond
)
->
Unit
(
benchmark
::
kMicrosecond
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_time_label_microsecond %console_us_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_time_label_microsecond
\"
,$"
},
{
"
\"
run_name
\"
:
\"
BM_time_label_microsecond
\"
,$"
,
MR_Next
},
{
"
\"
run_type
\"
:
\"
iteration
\"
,$"
,
MR_Next
},
{
"
\"
repetitions
\"
: 0,$"
,
MR_Next
},
{
"
\"
repetition_index
\"
: 0,$"
,
MR_Next
},
{
"
\"
threads
\"
: 1,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
cpu_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
time_unit
\"
:
\"
us
\"
$"
,
MR_Next
},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_time_label_microsecond
\"
,%csv_us_report$"
}});
void
BM_time_label_millisecond
(
benchmark
::
State
&
state
)
{
for
(
auto
_
:
state
)
{
}
}
BENCHMARK
(
BM_time_label_millisecond
)
->
Unit
(
benchmark
::
kMillisecond
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_time_label_millisecond %console_ms_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_time_label_millisecond
\"
,$"
},
{
"
\"
run_name
\"
:
\"
BM_time_label_millisecond
\"
,$"
,
MR_Next
},
{
"
\"
run_type
\"
:
\"
iteration
\"
,$"
,
MR_Next
},
{
"
\"
repetitions
\"
: 0,$"
,
MR_Next
},
{
"
\"
repetition_index
\"
: 0,$"
,
MR_Next
},
{
"
\"
threads
\"
: 1,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
cpu_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
time_unit
\"
:
\"
ms
\"
$"
,
MR_Next
},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_time_label_millisecond
\"
,%csv_ms_report$"
}});
void
BM_time_label_second
(
benchmark
::
State
&
state
)
{
for
(
auto
_
:
state
)
{
}
}
BENCHMARK
(
BM_time_label_second
)
->
Unit
(
benchmark
::
kSecond
);
ADD_CASES
(
TC_ConsoleOut
,
{{
"^BM_time_label_second %console_s_report$"
}});
ADD_CASES
(
TC_JSONOut
,
{{
"
\"
name
\"
:
\"
BM_time_label_second
\"
,$"
},
{
"
\"
run_name
\"
:
\"
BM_time_label_second
\"
,$"
,
MR_Next
},
{
"
\"
run_type
\"
:
\"
iteration
\"
,$"
,
MR_Next
},
{
"
\"
repetitions
\"
: 0,$"
,
MR_Next
},
{
"
\"
repetition_index
\"
: 0,$"
,
MR_Next
},
{
"
\"
threads
\"
: 1,$"
,
MR_Next
},
{
"
\"
iterations
\"
: %int,$"
,
MR_Next
},
{
"
\"
real_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
cpu_time
\"
: %float,$"
,
MR_Next
},
{
"
\"
time_unit
\"
:
\"
s
\"
$"
,
MR_Next
},
{
"}"
,
MR_Next
}});
ADD_CASES
(
TC_CSVOut
,
{{
"^
\"
BM_time_label_second
\"
,%csv_s_report$"
}});
// ========================================================================= //
// ------------------------ Testing Error Output --------------------------- //
// ------------------------ Testing Error 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