Skip to content

Commit

Permalink
Refactor and fix some issue with the histogram code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Jan 3, 2016
1 parent 7c75e54 commit 321641f
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions src/pytest_benchmark/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,16 @@ def _tooltip_data(self, node, value, x, y, classes=None, xlabel=None):
self.svg.node(node, 'desc', class_="x_label").text = self.annotations[xlabel]["name"]


def make_plot(name, table, current, annotations, title, adjustment):
def make_plot(benchmarks, title, adjustment):
class Style(DefaultStyle):
colors = []
colors = ["#000000" if row["path"] else DefaultStyle.colors[0]
for row in benchmarks]
font_family = 'Consolas, "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace'

for label, row in table:
if label == current:
colors.append(DefaultStyle.colors[0])
else:
colors.append("#000000")

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

try:
Expand All @@ -64,10 +59,10 @@ class Style(DefaultStyle):
}

plot = Plot(
annotations,
benchmarks,
box_mode='tukey',
x_label_rotation=-90,
x_labels=[_["source"] for label, _ in table],
x_labels=[row["source"] for row in benchmarks],
show_legend=False,
title=title,
x_title="Trial",
Expand All @@ -82,9 +77,6 @@ class Style(DefaultStyle):
"file://style.css",
"file://graph.css",
"""inline:
.axis.x text {
xtext-anchor: middle !important;
}
.tooltip .value {
font-size: 1em !important;
}
Expand All @@ -93,11 +85,10 @@ class Style(DefaultStyle):
**opts
)

for label, row in table:
if label in annotations:
label += "\n@%s - %s rounds" % (annotations[label]["datetime"], row["rounds"])
for row in benchmarks:
label = "%s\n%s rounds" % (row["path"], row["rounds"])
serie = [row[field] * adjustment for field in ["min", "ld15iqr", "q1", "median", "q3", "hd15iqr", "max"]]
plot.add(row["source"], serie)
plot.add(label, serie)
return plot


Expand All @@ -110,17 +101,9 @@ def make_histogram(output_prefix, name, benchmarks, unit, adjustment):
title = "Speed in %s" % TIME_UNITS[unit]

output_file = py.path.local(path).ensure()
current = None
table = list(enumerate(benchmarks))
for pos, bench in table:
if bench["path"] is None:
current = pos

plot = make_plot(
name=name,
table=table,
current=current,
annotations=benchmarks,
benchmarks=benchmarks,
title=title,
adjustment=adjustment,
)
Expand Down

0 comments on commit 321641f

Please sign in to comment.