Skip to content

Commit 29d1722

Browse files
committed
Add an output style for GitHub tables.
1 parent ec9e291 commit 29d1722

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

pyperformance/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ def parse_args():
113113
cmd.add_argument("-v", "--verbose", action="store_true",
114114
help="Print more output")
115115
cmd.add_argument("-O", "--output_style", metavar="STYLE",
116-
choices=("normal", "table"),
116+
choices=("normal", "table", "table_github"),
117117
default="normal",
118118
help=("What style the benchmark output should take."
119-
" Valid options are 'normal' and 'table'."
119+
" Valid options are 'normal', 'table', and 'table_github'."
120120
" Default is normal."))
121121
cmd.add_argument("--csv", metavar="CSV_FILE",
122122
action="store", default=None,

pyperformance/compare.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ def format_table(base_label, changed_label, results):
202202
output.insert(2, "".join(header_sep_line))
203203
return "\n".join(output)
204204

205+
def _format_github_row(items):
206+
return "| " + " | ".join(items) + " |"
207+
208+
def format_github_table(base_label, changed_label, results):
209+
columns = ("Benchmark", base_label, changed_label, "Change", "Significance")
210+
output = [_format_github_row(columns), "| --- " * len(columns) + "|"]
211+
212+
for (bench_name, result) in results:
213+
format_value = result.base.format_value
214+
avg_base = result.base.mean()
215+
avg_changed = result.changed.mean()
216+
delta_avg = quantity_delta(result.base, result.changed)
217+
msg = significant_msg(result.base, result.changed)
218+
rows = (bench_name,
219+
# Limit the precision for conciseness in the table.
220+
format_value(avg_base),
221+
format_value(avg_changed),
222+
delta_avg,
223+
msg)
224+
output.append(_format_github_row(rows))
225+
226+
return "\n".join(output)
227+
205228

206229
class BenchmarkResult(object):
207230
"""An object representing data from a succesful benchmark run."""
@@ -355,6 +378,9 @@ def compare_results(options):
355378
elif options.output_style == "table":
356379
if shown:
357380
print(format_table(base_label, changed_label, shown))
381+
elif options.output_style == "table_github":
382+
if shown:
383+
print(format_github_table(base_label, changed_label, shown))
358384
else:
359385
raise ValueError("Invalid output_style: %r" % options.output_style)
360386

0 commit comments

Comments
 (0)