-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_plots.py
74 lines (57 loc) · 2.06 KB
/
benchmark_plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
from collections import defaultdict
import matplotlib.pyplot as plt
import numpy as np
def plotit(stats, python_versions, label):
labels = ["avro", "fastavro"]
avro_ops = stats["avro"]
fastavro_ops = stats["fastavro"]
x = np.arange(len(labels))
width = 0.2
fig, ax = plt.subplots(figsize=(10, 12))
bars1 = ax.bar(x - width / 2, avro_ops, width, label="avro", color="orangered")
bars2 = ax.bar(
x + width / 2, fastavro_ops, width, label="fastavro", color="dodgerblue"
)
ax.set_ylabel("ops/s")
ax.set_xticks(x)
ax.set_xticklabels(python_versions)
ax.set_title("{} benchmark".format(label), color="black", fontweight="bold")
ax.legend()
autolabel(ax, bars1)
autolabel(ax, bars2)
fig.tight_layout()
plt.show()
def autolabel(ax, bars):
"""Attach a text label above each bar in *rects*, displaying its height."""
for bar in bars:
height = bar.get_height()
ax.annotate(
"{0:.2f}".format(height),
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3),
textcoords="offset points",
ha="center",
va="bottom",
)
def read_ops_stats(group, python_versions):
stats = defaultdict(list)
for python_version in python_versions:
with open("reports/benchmark-{}.json".format(python_version), "r") as f:
data = json.loads(f.read())
for benchmark in data["benchmarks"]:
if benchmark["group"] == group:
if "fastavro" in benchmark["name"]:
stats["fastavro"].append(benchmark["stats"]["ops"])
else:
stats["avro"].append(benchmark["stats"]["ops"])
return stats
if __name__ == "__main__":
benchmark_groups = ["Encoders", "Decoders"]
python_versions = ["python3.7", "python3.8"]
for bg in benchmark_groups:
plotit(
stats=read_ops_stats(bg, python_versions),
python_versions=python_versions,
label=bg,
)