-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasure.py
executable file
·69 lines (45 loc) · 1.27 KB
/
measure.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
#!/usr/bin/env python3
import os
import re
import timeit
def find_all(name, path):
out = []
for root, dirs, files in os.walk(path):
if name in files:
out.append(os.path.join(root, name))
return out
solvers = find_all("input", ".")
p_path = re.compile(r"^[.]/(?P<year>\d{4})/day(?P<day>\d+)/.*$")
puzzles = dict()
home = os.getcwd()
solvers = sorted(solvers)
for solver in solvers:
m = p_path.match(solver)
if m:
year = m["year"]
day = m["day"]
os.chdir(str(year))
call = lambda: os.system(f"python -m day{day}.solve > /dev/null")
reps, time_total = timeit.Timer(call).autorange()
puzzles[(int(year), int(day))] = {
"reps": reps,
"total": time_total,
"avg": time_total / reps
}
os.chdir(home)
update = [["year", "day", "avg"]]
for (year, day), v in puzzles.items():
avg = v["avg"]
print(year, f"{day:2}:", f"{avg:0.3f}", end="")
if avg >= 5:
print("\t!!!")
else:
print()
if day < 10:
day = f"0{day}"
update.append([str(year), str(day), f"{avg:.3f}"])
update = [",".join(x) for x in update]
update.append("")
update = f"{os.linesep}".join(update)
with open("performance.csv", "w+") as file:
file.write(update)