-
Notifications
You must be signed in to change notification settings - Fork 9
/
plot.py
executable file
·75 lines (57 loc) · 2.03 KB
/
plot.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
#!/usr/bin/env python3
from matplotlib import pyplot as plt
import numpy as np
import json
import re
from pathlib import Path
script_dir = Path(__file__).parent.absolute()
def parse_line(line):
# Example line:
# 833MiB 0:00:01 [ 833MiB/s] [<=> ]
# Extracts ("833", "MiB")
pat = re.compile(r"[0-9.a-zA-Z\s]+ [0-9:]+ \[\s*([0-9.]+)\s*([a-zA-Z]+)/s\].*")
results = pat.findall(line)
if results:
value, unit = results[0]
return float(value) / (1 if unit == "GiB" else 1024)
print(f"Couldn't parse line: {line} with {pat} {results}")
return 0.0
def main():
with open(script_dir / "results.json", "r") as f:
results = json.load(f)
output_dir = script_dir / "results"
output_dir.mkdir(exist_ok=True)
for language, submissions in results.items():
parsed_results = {
k: [
parse_line(line) for line in v.splitlines()
] for k, v in submissions.items()
}
for submission, values in parsed_results.items():
p = plt.plot(values, ".", label=submission)
mean = np.mean(values)
plt.axhline(mean, color=p[0].get_color())
plt.legend()
plt.xlabel("Seconds")
plt.ylabel("GiB/s")
plt.title(language)
plt.gcf().set_size_inches(12, 8)
plt.savefig(output_dir / f"{language}.png")
plt.clf()
for language, submissions in results.items():
parsed_results = {
k: [
parse_line(line) for line in v.splitlines()
] for k, v in submissions.items()
}
table = [
"| Author | Throughput |",
"| -------- | -------------- |"
]
row_template = "| {} | {:.1f} GiB/s |"
for submission, values in parsed_results.items():
table.append(row_template.format(submission, np.mean(values)))
print(f"# Results for {language}:")
print("\n".join(table))
if __name__ == "__main__":
main()