Skip to content

Commit

Permalink
Remove some cruft from the internal table. Also show the number of ro…
Browse files Browse the repository at this point in the history
…unds in the tooltip.
  • Loading branch information
ionelmc committed Aug 13, 2015
1 parent d061e81 commit 518f39b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
30 changes: 15 additions & 15 deletions src/pytest_benchmark/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ def __init__(self, annotations, *args, **kwargs):
self.annotations = annotations

def _box_points(self, serie, _):
return (serie[0],
return (None,
serie[0],
serie[1],
serie[2],
serie[3],
serie[4],
serie[4]), []
serie[5]), []

def _format(self, x):
sup = super(Box, self)._format
if is_list_like(x):
return 'Min: %s\nQ1: %s\nMedian: %s\nQ3: %s\nMax: %s' % tuple(map(sup, x[1:6]))
return 'Min: %s\nQ1: %s\nMedian: %s\nQ3: %s\nMax: %s\nRounds: %s' % tuple(map(sup, x[1:]))
else:
return sup(x)

def _tooltip_data(self, node, value, x, y, classes=None, xlabel=None):
super(Plot, self)._tooltip_data(node, value, x, y, classes=classes, xlabel=None)
if xlabel in self.annotations:
self.svg.node(node, 'desc', class_="x_label").text = self.annotations[xlabel]
self.svg.node(node, 'desc', class_="x_label").text = self.annotations[xlabel]['name']


def make_plot(bench_name, table, compare, current, annotations, sort):
class Style(DefaultStyle):
colors = []
font_family = 'Consolas, "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace'

for label, _, row in table:
for label, row in table:
if label == current:
colors.append(DefaultStyle.colors[0])
elif compare and str(compare.basename).startswith(label):
Expand All @@ -51,16 +51,16 @@ class Style(DefaultStyle):

unit, adjustment = time_unit(min(
row[sort]
for _, _, row in table
for _, row in table
))

minimum = int(min(row['min'] * adjustment for _, _, row in table))
maximum = int(max(row['max'] * adjustment for _, _, row in table) + 1)
minimum = int(min(row['min'] * adjustment for _, row in table))
maximum = int(max(row['max'] * adjustment for _, row in table) + 1)

plot = Plot(
annotations,
x_label_rotation=-90,
x_labels=[label for label, _, _ in table],
x_labels=[label for label, _ in table],
show_legend=False,
title="Speed in %sseconds of %s" % (unit, bench_name),
x_title="Trial",
Expand All @@ -80,10 +80,10 @@ class Style(DefaultStyle):
],
)

for label, info, row in table:
if info:
label += '\n@' + info
plot.add(label,
[row[field] * adjustment for field in ['min', 'q1', 'median', 'q3', 'max']],
stroke_style={'width': 1})
for label, row in table:
if label in annotations:
label += '\n@' + annotations[label]['datetime']
serie = [row[field] * adjustment for field in ['min', 'q1', 'median', 'q3', 'max']]
serie.append(row['rounds'])
plot.add(label, serie)
return plot
8 changes: 3 additions & 5 deletions src/pytest_benchmark/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def handle_histogram(self):
bench_name=bench.fullname,
table=table,
compare=self.compare_file,
annotations=dict((k, v['name']) for k, v in history.items()),
annotations=history,
sort=self.sort,
current=HISTOGRAM_CURRENT,
)
Expand All @@ -607,16 +607,14 @@ def generate_histogram_table(current, history, sequence):
for bench in trial['benchmarks']:
if bench['fullname'] == current.fullname:
found = True
# elif bench['name'] == current.name:
# found = True
else:
found = False

if found:
yield '%s' % name, trial['datetime'], bench['stats']
yield '%s' % name, bench['stats']
break

yield HISTOGRAM_CURRENT, "", current.json()
yield HISTOGRAM_CURRENT, current.json()

def display_results_table(self, tr):
timer = self.options.get('timer')
Expand Down

0 comments on commit 518f39b

Please sign in to comment.