1 """report.py - Utilities for reporting statistics about benchmark results
11 return '%s%r' % (self.__class__.__name__,
32 Return the result of 'fmt_str.format(*args, **kwargs)' after transforming
33 'args' and 'kwargs' according to the value of 'use_color'. If 'use_color'
34 is False then all color codes in 'args' and 'kwargs' are replaced with
37 assert use_color
is True or use_color
is False
39 args = [arg
if not isinstance(arg, BenchmarkColor)
else BC_NONE
41 kwargs = {key: arg
if not isinstance(arg, BenchmarkColor)
else BC_NONE
42 for key, arg
in kwargs.items()}
43 return fmt_str.format(*args, **kwargs)
48 Return the length of the longest benchmark name in a given list of
49 benchmark JSON objects
52 for bc
in benchmark_list:
53 if len(bc[
'name']) > longest_name:
54 longest_name =
len(bc[
'name'])
60 Return a float representing the decimal change between old_val and new_val.
62 if old_val == 0
and new_val == 0:
65 return float(new_val - old_val) / (float(old_val + new_val) / 2)
66 return float(new_val - old_val) / abs(old_val)
71 Calculate and report the difference between each test of two benchmarks
72 runs specified as 'json1' and 'json2'.
76 for b
in json2[
'benchmarks']:
80 first_line =
"{:<{}s} Time CPU Old New".format(
81 'Benchmark', first_col_width)
82 output_strs = [first_line,
'-' *
len(first_line)]
84 gen = (bn
for bn
in json1[
'benchmarks']
if 'real_time' in bn
and 'cpu_time' in bn)
86 other_bench = find_test(bn[
'name'])
97 fmt_str =
"{}{:<{}s}{endc}{}{:+9.2f}{endc}{}{:+14.2f}{endc}{:14d}{:14d}"
101 BC_HEADER, bn[
'name'], first_col_width,
102 get_color(tres), tres, get_color(cpures), cpures,
103 bn[
'cpu_time'], other_bench[
'cpu_time'],
115 testInputs = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'Inputs')
116 testOutput1 = os.path.join(testInputs,
'test1_run1.json')
117 testOutput2 = os.path.join(testInputs,
'test1_run2.json')
118 with open(testOutput1,
'r')
as f:
120 with open(testOutput2,
'r')
as f:
126 [
'BM_SameTimes',
'+0.00',
'+0.00',
'10',
'10'],
127 [
'BM_2xFaster',
'-0.50',
'-0.50',
'50',
'25'],
128 [
'BM_2xSlower',
'+1.00',
'+1.00',
'50',
'100'],
129 [
'BM_10PercentFaster',
'-0.10',
'-0.10',
'100',
'90'],
130 [
'BM_10PercentSlower',
'+0.10',
'+0.10',
'100',
'110'],
131 [
'BM_100xSlower',
'+99.00',
'+99.00',
'100',
'10000'],
132 [
'BM_100xFaster',
'-0.99',
'-0.99',
'10000',
'100'],
136 output_lines = output_lines_with_header[2:]
137 print(
"\n".join(output_lines_with_header))
138 self.assertEqual(
len(output_lines),
len(expect_lines))
139 for i
in xrange(0,
len(output_lines)):
140 parts = [x
for x
in output_lines[i].split(
' ')
if x]
141 self.assertEqual(
len(parts), 5)
142 self.assertEqual(parts, expect_lines[i])
145 if __name__ ==
'__main__':