-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerate-benchmark-graph.py
More file actions
103 lines (75 loc) · 2.39 KB
/
generate-benchmark-graph.py
File metadata and controls
103 lines (75 loc) · 2.39 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
import json
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import os
import sys
from pathlib import Path
OUTPUT_FILE = sys.argv[1]
BENCHMARK_FILE = Path(sys.argv[2])
YEAR = BENCHMARK_FILE.parts[1]
COLOURS = {"Python": "#3572A5", "Go": "#00ADD8"}
MAX_Y_VALUE = 1
runner_translation = {
"py": "Python",
"go": "Go",
}
benchmark_data = {
"Python": {},
"Go": {},
} # adding dicts here sets the order of points being plotted
with open(BENCHMARK_FILE) as f:
for line in f.readlines():
d = json.loads(line)
rn = runner_translation[d["runner"]]
benchmark_data[rn][f"{d['day']}.{d['part']}"] = d["avg"]
all_days = set()
for lang in benchmark_data:
for key in benchmark_data[lang]:
day = int(key.split(".", 1)[0])
all_days.add(day)
BAR_WIDTH = 0.45
datasets = []
for i, language in enumerate(benchmark_data):
data = benchmark_data[language]
part_one_times = []
part_two_times = []
p1days = []
p2days = []
for key in data:
day = int(key.split(".", 1)[0])
if key.endswith(".1"):
if day not in p1days:
p1days.append(day - (BAR_WIDTH / 2))
part_one_times.append(data[key])
if key.endswith(".2"):
if day not in p2days:
p2days.append(day + (BAR_WIDTH / 2))
part_two_times.append(data[key])
if len(part_one_times) == 0 and len(part_two_times) == 0:
break
datasets.append(((p1days, part_one_times), (p2days, part_two_times), language))
figure = plt.figure(figsize=(6 * len(datasets), 5))
fst = None
for i, (partone, parttwo, label) in enumerate(datasets):
axp = figure.add_subplot(1, len(datasets), i + 1, sharey=fst)
if fst is None:
fst = axp
axp.bar(*partone, color="#fb4934", width=BAR_WIDTH)
axp.bar(*parttwo, color="#fabd2f", width=BAR_WIDTH)
axp.axhline(y=15, color="#fc8080", linestyle="--")
axp.set_title(label)
plt.sca(axp)
plt.xticks(list(all_days), [str(y) for y in all_days])
plt.ylabel("Running time (log seconds)")
plt.yscale("log")
plt.xlabel("Day")
plt.legend(
handles=[
patches.Patch(color="#fb4934", label="Part one"),
patches.Patch(color="#fabd2f", label="Part two"),
]
)
figure.suptitle(f"{YEAR} challenge running time")
plt.tight_layout()
plt.savefig(OUTPUT_FILE)