@@ -45,11 +45,11 @@ def parse_lnt(lines):
45
45
results [name ][metric ].append (float (value ))
46
46
return results
47
47
48
- def plain_text_comparison (benchmarks , baseline , candidate ):
48
+ def plain_text_comparison (benchmarks , baseline , candidate , baseline_name = None , candidate_name = None ):
49
49
"""
50
50
Create a tabulated comparison of the baseline and the candidate.
51
51
"""
52
- headers = ['Benchmark' , 'Baseline' , 'Candidate' , 'Difference' , '% Difference' ]
52
+ headers = ['Benchmark' , baseline_name , candidate_name , 'Difference' , '% Difference' ]
53
53
fmt = (None , '.2f' , '.2f' , '.2f' , '.2f' )
54
54
table = []
55
55
for (bm , base , cand ) in zip (benchmarks , baseline , candidate ):
@@ -59,13 +59,18 @@ def plain_text_comparison(benchmarks, baseline, candidate):
59
59
table .append (row )
60
60
return tabulate .tabulate (table , headers = headers , floatfmt = fmt , numalign = 'right' )
61
61
62
- def create_chart (benchmarks , baseline , candidate ):
62
+ def create_chart (benchmarks , baseline , candidate , subtitle = None , baseline_name = None , candidate_name = None ):
63
63
"""
64
64
Create a bar chart comparing 'baseline' and 'candidate'.
65
65
"""
66
- figure = plotly .graph_objects .Figure ()
67
- figure .add_trace (plotly .graph_objects .Bar (x = benchmarks , y = baseline , name = 'Baseline' ))
68
- figure .add_trace (plotly .graph_objects .Bar (x = benchmarks , y = candidate , name = 'Candidate' ))
66
+ figure = plotly .graph_objects .Figure (layout = {
67
+ 'title' : {
68
+ 'text' : f'{ baseline_name } vs { candidate_name } ' ,
69
+ 'subtitle' : {'text' : subtitle }
70
+ }
71
+ })
72
+ figure .add_trace (plotly .graph_objects .Bar (x = benchmarks , y = baseline , name = baseline_name ))
73
+ figure .add_trace (plotly .graph_objects .Bar (x = benchmarks , y = candidate , name = candidate_name ))
69
74
return figure
70
75
71
76
def prepare_series (baseline , candidate , metric , aggregate = statistics .median ):
@@ -107,8 +112,18 @@ def main(argv):
107
112
parser .add_argument ('--open' , action = 'store_true' ,
108
113
help = 'Whether to automatically open the generated HTML file when finished. This option only makes sense '
109
114
'when the output format is `chart`.' )
115
+ parser .add_argument ('--baseline-name' , type = str , default = 'Baseline' ,
116
+ help = 'Optional name to use for the "baseline" label.' )
117
+ parser .add_argument ('--candidate-name' , type = str , default = 'Candidate' ,
118
+ help = 'Optional name to use for the "candidate" label.' )
119
+ parser .add_argument ('--subtitle' , type = str , required = False ,
120
+ help = 'Optional subtitle to use for the chart. This can be used to help identify the contents of the chart. '
121
+ 'This option cannot be used with the plain text output.' )
110
122
args = parser .parse_args (argv )
111
123
124
+ if args .format == 'text' and args .subtitle is not None :
125
+ parser .error ('Passing --subtitle makes no sense with --format=text' )
126
+
112
127
if args .format == 'text' and args .open :
113
128
parser .error ('Passing --open makes no sense with --format=text' )
114
129
@@ -123,12 +138,15 @@ def main(argv):
123
138
(benchmarks , baseline_series , candidate_series ) = prepare_series (baseline , candidate , args .metric )
124
139
125
140
if args .format == 'chart' :
126
- figure = create_chart (benchmarks , baseline_series , candidate_series )
141
+ figure = create_chart (benchmarks , baseline_series , candidate_series , subtitle = args .subtitle ,
142
+ baseline_name = args .baseline_name ,
143
+ candidate_name = args .candidate_name )
127
144
do_open = args .output is None or args .open
128
145
output = args .output or tempfile .NamedTemporaryFile (suffix = '.html' ).name
129
146
plotly .io .write_html (figure , file = output , auto_open = do_open )
130
147
else :
131
- diff = plain_text_comparison (benchmarks , baseline_series , candidate_series )
148
+ diff = plain_text_comparison (benchmarks , baseline_series , candidate_series , baseline_name = args .baseline_name ,
149
+ candidate_name = args .candidate_name )
132
150
diff += '\n '
133
151
if args .output is not None :
134
152
with open (args .output , 'w' ) as out :
0 commit comments