aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2017-07-25 02:13:55 +0300
committerDominic Hamon <dominichamon@users.noreply.github.com>2017-07-24 16:13:55 -0700
commitb9be142d1e2dbc06cf2efd44919f6c422c43cddb (patch)
tree2cbabb4cb8964a992928bb1a89a5d97f68a37dfe /tools
parent5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8 (diff)
downloadgoogle-benchmark-b9be142d1e2dbc06cf2efd44919f6c422c43cddb.tar.gz
Json reporter: don't cast floating-point to int; adjust tooling (#426)
* Json reporter: passthrough fp, don't cast it to int; adjust tooling Json output format is generally meant for further processing using some automated tools. Thus, it makes sense not to intentionally limit the precision of the values contained in the report. As it can be seen, FormatKV() for doubles, used %.2f format, which was meant to preserve at least some of the precision. However, before that function is ever called, the doubles were already cast to the integer via RoundDouble()... This is also the case for console reporter, where it makes sense because the screen space is limited, and this reporter, however the CSV reporter does output some( decimal digits. Thus i can only conclude that the loss of the precision was not really considered, so i have decided to adjust the code of the json reporter to output the full fp precision. There can be several reasons why that is the right thing to do, the bigger the time_unit used, the greater the precision loss, so i'd say any sort of further processing (like e.g. tools/compare_bench.py does) is best done on the values with most precision. Also, that cast skewed the data away from zero, which i think may or may not result in false- positives/negatives in the output of tools/compare_bench.py * Json reporter: FormatKV(double): address review note * tools/gbench/report.py: skip benchmarks with different time units While it may be useful to teach it to operate on the measurements with different time units, which is now possible since floats are stored, and not the integers, but for now at least doing such a sanity-checking is better than providing misinformation.
Diffstat (limited to 'tools')
-rw-r--r--tools/gbench/Inputs/test1_run1.json23
-rw-r--r--tools/gbench/Inputs/test1_run2.json27
-rw-r--r--tools/gbench/report.py7
3 files changed, 52 insertions, 5 deletions
diff --git a/tools/gbench/Inputs/test1_run1.json b/tools/gbench/Inputs/test1_run1.json
index 37faed4..262eeaf 100644
--- a/tools/gbench/Inputs/test1_run1.json
+++ b/tools/gbench/Inputs/test1_run1.json
@@ -29,6 +29,20 @@
"time_unit": "ns"
},
{
+ "name": "BM_1PercentFaster",
+ "iterations": 1000,
+ "real_time": 100,
+ "cpu_time": 100,
+ "time_unit": "ns"
+ },
+ {
+ "name": "BM_1PercentSlower",
+ "iterations": 1000,
+ "real_time": 100,
+ "cpu_time": 100,
+ "time_unit": "ns"
+ },
+ {
"name": "BM_10PercentFaster",
"iterations": 1000,
"real_time": 100,
@@ -55,6 +69,13 @@
"real_time": 10000,
"cpu_time": 10000,
"time_unit": "ns"
+ },
+ {
+ "name": "BM_DifferentTimeUnit",
+ "iterations": 1,
+ "real_time": 1,
+ "cpu_time": 1,
+ "time_unit": "s"
}
]
-} \ No newline at end of file
+}
diff --git a/tools/gbench/Inputs/test1_run2.json b/tools/gbench/Inputs/test1_run2.json
index aed5151..21e0fd1 100644
--- a/tools/gbench/Inputs/test1_run2.json
+++ b/tools/gbench/Inputs/test1_run2.json
@@ -29,6 +29,20 @@
"time_unit": "ns"
},
{
+ "name": "BM_1PercentFaster",
+ "iterations": 1000,
+ "real_time": 98.9999999,
+ "cpu_time": 98.9999999,
+ "time_unit": "ns"
+ },
+ {
+ "name": "BM_1PercentSlower",
+ "iterations": 1000,
+ "real_time": 100.9999999,
+ "cpu_time": 100.9999999,
+ "time_unit": "ns"
+ },
+ {
"name": "BM_10PercentFaster",
"iterations": 1000,
"real_time": 90,
@@ -45,8 +59,8 @@
{
"name": "BM_100xSlower",
"iterations": 1000,
- "real_time": 10000,
- "cpu_time": 10000,
+ "real_time": 1.0000e+04,
+ "cpu_time": 1.0000e+04,
"time_unit": "ns"
},
{
@@ -55,6 +69,13 @@
"real_time": 100,
"cpu_time": 100,
"time_unit": "ns"
+ },
+ {
+ "name": "BM_DifferentTimeUnit",
+ "iterations": 1,
+ "real_time": 1,
+ "cpu_time": 1,
+ "time_unit": "ns"
}
]
-} \ No newline at end of file
+}
diff --git a/tools/gbench/report.py b/tools/gbench/report.py
index 015d33d..dee7b24 100644
--- a/tools/gbench/report.py
+++ b/tools/gbench/report.py
@@ -87,6 +87,9 @@ def generate_difference_report(json1, json2, use_color=True):
if not other_bench:
continue
+ if bn['time_unit'] != other_bench['time_unit']:
+ continue
+
def get_color(res):
if res > 0.05:
return BC_FAIL
@@ -94,7 +97,7 @@ def generate_difference_report(json1, json2, use_color=True):
return BC_WHITE
else:
return BC_CYAN
- fmt_str = "{}{:<{}s}{endc}{}{:+9.2f}{endc}{}{:+14.2f}{endc}{:14d}{:14d}"
+ fmt_str = "{}{:<{}s}{endc}{}{:+9.2f}{endc}{}{:+14.2f}{endc}{:14.0f}{:14.0f}"
tres = calculate_change(bn['real_time'], other_bench['real_time'])
cpures = calculate_change(bn['cpu_time'], other_bench['cpu_time'])
output_strs += [color_format(use_color, fmt_str,
@@ -126,6 +129,8 @@ class TestReportDifference(unittest.TestCase):
['BM_SameTimes', '+0.00', '+0.00', '10', '10'],
['BM_2xFaster', '-0.50', '-0.50', '50', '25'],
['BM_2xSlower', '+1.00', '+1.00', '50', '100'],
+ ['BM_1PercentFaster', '-0.01', '-0.01', '100', '99'],
+ ['BM_1PercentSlower', '+0.01', '+0.01', '100', '101'],
['BM_10PercentFaster', '-0.10', '-0.10', '100', '90'],
['BM_10PercentSlower', '+0.10', '+0.10', '100', '110'],
['BM_100xSlower', '+99.00', '+99.00', '100', '10000'],