Skip to content

Commit e381139

Browse files
pcamprEricWF
authored andcommitted
fix compare script - output formatting - correctly align numbers >9999 (google#322)
* fix compare script - output formatting - correctly align numbers >9999 * fix failing test (report.py); fix compare script output formatting (large numbers alignment)
1 parent 56336e7 commit e381139

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

tools/gbench/Inputs/test1_run1.json

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@
4141
"real_time": 100,
4242
"cpu_time": 100,
4343
"time_unit": "ns"
44+
},
45+
{
46+
"name": "BM_100xSlower",
47+
"iterations": 1000,
48+
"real_time": 100,
49+
"cpu_time": 100,
50+
"time_unit": "ns"
51+
},
52+
{
53+
"name": "BM_100xFaster",
54+
"iterations": 1000,
55+
"real_time": 10000,
56+
"cpu_time": 10000,
57+
"time_unit": "ns"
4458
}
4559
]
4660
}

tools/gbench/Inputs/test1_run2.json

+14
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@
4141
"real_time": 110,
4242
"cpu_time": 110,
4343
"time_unit": "ns"
44+
},
45+
{
46+
"name": "BM_100xSlower",
47+
"iterations": 1000,
48+
"real_time": 10000,
49+
"cpu_time": 10000,
50+
"time_unit": "ns"
51+
},
52+
{
53+
"name": "BM_100xFaster",
54+
"iterations": 1000,
55+
"real_time": 100,
56+
"cpu_time": 100,
57+
"time_unit": "ns"
4458
}
4559
]
4660
}

tools/gbench/report.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def get_color(res):
9292
return BC_WHITE
9393
else:
9494
return BC_CYAN
95-
fmt_str = "{}{:<{}s}{endc} {}{:+.2f}{endc} {}{:+.2f}{endc} {:4d} {:4d}"
95+
fmt_str = "{}{:<{}s}{endc}{}{:+9.2f}{endc}{}{:+14.2f}{endc}{:14d}{:14d}"
9696
tres = calculate_change(bn['real_time'], other_bench['real_time'])
9797
cpures = calculate_change(bn['cpu_time'], other_bench['cpu_time'])
9898
output_strs += [color_format(use_color, fmt_str,
@@ -121,19 +121,22 @@ def load_results(self):
121121

122122
def test_basic(self):
123123
expect_lines = [
124-
['BM_SameTimes', '+0.00', '+0.00'],
125-
['BM_2xFaster', '-0.50', '-0.50'],
126-
['BM_2xSlower', '+1.00', '+1.00'],
127-
['BM_10PercentFaster', '-0.10', '-0.10'],
128-
['BM_10PercentSlower', '+0.10', '+0.10']
124+
['BM_SameTimes', '+0.00', '+0.00', '10', '10'],
125+
['BM_2xFaster', '-0.50', '-0.50', '50', '25'],
126+
['BM_2xSlower', '+1.00', '+1.00', '50', '100'],
127+
['BM_10PercentFaster', '-0.10', '-0.10', '100', '90'],
128+
['BM_10PercentSlower', '+0.10', '+0.10', '100', '110'],
129+
['BM_100xSlower', '+99.00', '+99.00', '100', '10000'],
130+
['BM_100xFaster', '-0.99', '-0.99', '10000', '100'],
129131
]
130132
json1, json2 = self.load_results()
131-
output_lines = generate_difference_report(json1, json2, use_color=False)
132-
print output_lines
133+
output_lines_with_header = generate_difference_report(json1, json2, use_color=False)
134+
output_lines = output_lines_with_header[2:]
135+
print "\n".join(output_lines_with_header)
133136
self.assertEqual(len(output_lines), len(expect_lines))
134137
for i in xrange(0, len(output_lines)):
135138
parts = [x for x in output_lines[i].split(' ') if x]
136-
self.assertEqual(len(parts), 3)
139+
self.assertEqual(len(parts), 5)
137140
self.assertEqual(parts, expect_lines[i])
138141

139142

0 commit comments

Comments
 (0)