-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate-benchmark-graph.py
120 lines (92 loc) · 2.9 KB
/
generate-benchmark-graph.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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)
figure = plt.figure(figsize=(25 / 2, 5))
axp1 = figure.add_subplot(1, 2, 1)
axp2 = figure.add_subplot(1, 2, 2, sharey=axp1)
axp1.axhline(y=15, color="#fc8080", linestyle="--")
axp2.axhline(y=15, color="#fc8080", linestyle="--")
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)
part_one_times.append(data[key])
if key.endswith(".2"):
if day not in p2days:
p2days.append(day)
part_two_times.append(data[key])
colour = COLOURS.get(language)
p1 = axp1.scatter(p1days, part_one_times, color=colour)
p2 = axp2.scatter(p2days, part_two_times, color=colour)
for i, day in enumerate(p1days):
if i + 1 >= len(p1days):
continue
if p1days[i + 1] == day + 1:
axp1.plot(
(day, p1days[i + 1]),
(part_one_times[i], part_one_times[i + 1]),
"-",
color=colour,
)
for i, day in enumerate(p2days):
if i + 1 >= len(p2days):
continue
if p2days[i + 1] == day + 1:
axp2.plot(
(day, p2days[i + 1]),
(part_two_times[i], part_two_times[i + 1]),
"-",
color=colour,
)
figure.suptitle(f"Average {YEAR} challenge running time")
axp1.set_title("Part one")
axp2.set_title("Part two")
def do_auxillary_parts(axis):
plt.sca(axis)
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=COLOURS[label], label=label) for label in COLOURS]
)
# plt.ylim([0, MAX_Y_VALUE])
# plt.legend(legends)
do_auxillary_parts(axp1)
do_auxillary_parts(axp2)
plt.tight_layout()
plt.savefig(OUTPUT_FILE)