/
timeaoc.py
39 lines (31 loc) · 871 Bytes
/
timeaoc.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
import time, sys
from importlib import reload
try:
num = sys.argv[1]
except:
print("Specify file, e.g. 9a, 10b, 11c, or full file name")
print("Optional 2nd parameter is number of rounds")
sys.exit()
if num.endswith('.py'):
num = num[:-3]
if len(num)<4 and num[0].isdigit() and num[-1] in ('abcdef'):
command = f'reload(aoc_{num:0>3})'
scommand = f'import aoc_{num:0>3}'
else:
command = f'reload({num})'
scommand = f'import {num}'
runtimes = []
try:
rounds = int(sys.argv[2])
except:
rounds = 20
print("Discarding startup round")
exec(scommand)
print("Startup round discarded\n")
for _ in range(rounds):
starttime = time.perf_counter()
exec(command)
runtime = time.perf_counter()-starttime
# print(f"{runtime:.6f}")
runtimes.append(runtime)
print(f"Minimum of {rounds} rounds: {min(runtimes):.6f}")