Skip to content
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

ENH: Add a markdown renderer for asv compare #1263

Merged
merged 5 commits into from
Apr 20, 2023
Merged
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 .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install:
- conda update conda -y
- conda install -q --yes python=%PYTHON_VERSION% conda pip pytest pytest-xdist pytest-timeout filelock selenium conda-build bzip2 pympler
- python -m pip install -U pip
- python -m pip install pytest-rerunfailures json5 pympler
- python -m pip install pytest-rerunfailures json5 pympler tabulate

# Check that we have the expected version of Python
- python --version
Expand Down
2 changes: 1 addition & 1 deletion asv/commands/common_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def add_compare(parser, only_changed_default=False, sort_default='name'):
parser.add_argument('--no-only-changed', dest='only_changed', action='store_false')

parser.add_argument(
'--sort', action='store', type=str, choices=('name', 'ratio'),
'--sort', action='store', type=str, choices=('name', 'ratio', 'default'),
default=sort_default, help="""Sort order""")


Expand Down
47 changes: 26 additions & 21 deletions asv/commands/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import itertools
import math

import tabulate

from . import Command, common_args
from ..benchmarks import Benchmarks
from ..machine import iter_machine_files
Expand Down Expand Up @@ -97,7 +99,7 @@ def setup_arguments(cls, subparsers):
'revision2',
help="""The revision being compared.""")

common_args.add_compare(parser, sort_default='name', only_changed_default=False)
common_args.add_compare(parser, sort_default='default', only_changed_default=False)

parser.add_argument(
'--machine', '-m', type=str, default=None,
Expand All @@ -122,7 +124,7 @@ def run_from_conf_args(cls, conf, args):

@classmethod
def run(cls, conf, hash_1, hash_2, factor=None, split=False, only_changed=False,
sort='name', machine=None, env_spec=None, use_stats=True):
sort='default', machine=None, env_spec=None, use_stats=True):

repo = get_repo(conf)
try:
Expand Down Expand Up @@ -170,8 +172,8 @@ def run(cls, conf, hash_1, hash_2, factor=None, split=False, only_changed=False,
@classmethod
def print_table(cls, conf, hash_1, hash_2, factor, split,
resultset_1=None, resultset_2=None, machine=None,
only_changed=False, sort='name', use_stats=True, env_names=None,
commit_names=None):
only_changed=False, sort='default',
use_stats=True, env_names=None, commit_names=None):
results_1 = {}
results_2 = {}
ss_1 = {}
Expand Down Expand Up @@ -340,11 +342,19 @@ def results_default_iter(commit_hash):
human_value(time_1, unit, err=err_1),
human_value(time_2, unit, err=err_2),
ratio)

split_line = details.split()
if len(machine_env_names) > 1:
benchmark_name = "{} [{}]".format(*benchmark)
else:
benchmark_name = benchmark[0]
if len(split_line) == 4:
split_line += [benchmark_name]
else:
split_line = [' '] + split_line + [benchmark_name]
if split:
bench[color].append((color, details, benchmark, ratio_num))
bench[color].append(split_line)
else:
bench['all'].append((color, details, benchmark, ratio_num))
bench['all'].append(split_line)

if split:
keys = ['green', 'default', 'red', 'lightgrey']
Expand All @@ -369,8 +379,6 @@ def results_default_iter(commit_hash):
color_print("")
color_print(titles[key])
color_print("")
color_print(" before after ratio")
color_print(" [{0:8s}] [{1:8s}]".format(hash_1[:8], hash_2[:8]))

name_1 = commit_names.get(hash_1)
if name_1:
Expand All @@ -384,23 +392,20 @@ def results_default_iter(commit_hash):
else:
name_2 = ''

if name_1 or name_2:
color_print(" {0:10s} {1:10s}".format(name_1, name_2))

if sort == 'ratio':
if sort == 'default':
pass
elif sort == 'ratio':
bench[key].sort(key=lambda v: v[3], reverse=True)
elif sort == 'name':
bench[key].sort(key=lambda v: v[2])
else:
raise ValueError("Unknown 'sort'")

for color, details, benchmark, ratio in bench[key]:
if len(machine_env_names) > 1:
benchmark_name = "{} [{}]".format(*benchmark)
else:
benchmark_name = benchmark[0]

color_print(details, color, end='')
color_print(benchmark_name)
print(tabulate.tabulate(bench[key],
headers=['Change',
f'Before [{hash_1[:8]}] {name_1}',
f'After [{hash_2[:8]}] {name_2}',
'Ratio', 'Benchmark (Parameter)'],
tablefmt="github"))

return worsened, improved
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ python-hglib
flake8
isort>= 5.11.5
json5
tabulate
pympler; platform_python_implementation != "PyPy"
pyyaml
Loading