-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.py
executable file
·49 lines (32 loc) · 963 Bytes
/
time.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
#!/usr/bin/env python3
from cli.run import run_problem, problem_exists
from time import time
MAX_LINE = 15
def time_solution(n):
start = time()
run_problem(n)
return time() - start
def format_line(n, t):
head = ('Problem %s:' % n).ljust(11)
if t > 1:
t2 = round(t, 3)
unit = 's'
else:
t2 = round(t * 1000, 1)
unit = 'ms'
tt = '[ %s %s ]' % (('%s' % t2).rjust(6), unit.ljust(2))
line = '=' * round(t / MAX_LINE * 80)
return '%s %s %s' % (head, tt, line)
def time_solutions():
start = time()
n = 1
while problem_exists(n):
print(format_line(n, time_solution(n)))
n += 1
duration = time() - start
print('%s problems solved in %s seconds' % (n-1, round(duration, 1)))
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser(description='Times solutions')
args = parser.parse_args()
time_solutions()