Skip to content

Add a comparison output style for GitHub tables #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ options::
-v, --verbose Print more output
-O STYLE, --output_style STYLE
What style the benchmark output should take.
Valid options are 'normal' and 'table'.
Valid options are 'normal', 'table', and 'table_github'.
Default is normal.
--csv CSV_FILE Name of a file the results will be written to,
as a three-column CSV file containing minimum
Expand Down
4 changes: 2 additions & 2 deletions pyperformance/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def parse_args():
cmd.add_argument("-v", "--verbose", action="store_true",
help="Print more output")
cmd.add_argument("-O", "--output_style", metavar="STYLE",
choices=("normal", "table"),
choices=("normal", "table", "table_github"),
default="normal",
help=("What style the benchmark output should take."
" Valid options are 'normal' and 'table'."
" Valid options are 'normal', 'table', and 'table_github'."
" Default is normal."))
cmd.add_argument("--csv", metavar="CSV_FILE",
action="store", default=None,
Expand Down
26 changes: 26 additions & 0 deletions pyperformance/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,29 @@ def format_table(base_label, changed_label, results):
output.insert(2, "".join(header_sep_line))
return "\n".join(output)

def _format_github_row(items):
return "| " + " | ".join(items) + " |"

def format_github_table(base_label, changed_label, results):
columns = ("Benchmark", base_label, changed_label, "Change", "Significance")
output = [_format_github_row(columns), "| --- " * len(columns) + "|"]

for (bench_name, result) in results:
format_value = result.base.format_value
avg_base = result.base.mean()
avg_changed = result.changed.mean()
delta_avg = quantity_delta(result.base, result.changed)
msg = significant_msg(result.base, result.changed)
rows = (bench_name,
# Limit the precision for conciseness in the table.
format_value(avg_base),
format_value(avg_changed),
delta_avg,
msg)
output.append(_format_github_row(rows))

return "\n".join(output)


class BenchmarkResult(object):
"""An object representing data from a succesful benchmark run."""
Expand Down Expand Up @@ -355,6 +378,9 @@ def compare_results(options):
elif options.output_style == "table":
if shown:
print(format_table(base_label, changed_label, shown))
elif options.output_style == "table_github":
if shown:
print(format_github_table(base_label, changed_label, shown))
else:
raise ValueError("Invalid output_style: %r" % options.output_style)

Expand Down
Loading