|
4 | 4 | import inspect
|
5 | 5 | from importlib import import_module
|
6 | 6 | from pathlib import Path
|
7 |
| -from traceback import print_exc |
8 |
| -from time import perf_counter |
9 | 7 | from timeit import timeit
|
10 | 8 | from functools import wraps
|
11 | 9 |
|
|
16 | 14 | def perf(f):
|
17 | 15 | @wraps(f)
|
18 | 16 | def wrapper(*args, **kwds):
|
19 |
| - start_time = perf_counter() |
20 | 17 | output = f(*args, **kwds)
|
21 |
| - time = perf_counter() - start_time |
22 | 18 | tit = timeit('f(*args, **kwds)', number=10**2, globals=locals())
|
23 |
| - return output, tit, time |
| 19 | + return output, tit |
24 | 20 | return wrapper
|
25 | 21 |
|
26 | 22 |
|
@@ -67,15 +63,17 @@ def handle(self):
|
67 | 63 | continue
|
68 | 64 | with open(input_file) as f:
|
69 | 65 | input_data = cast_func(f.read())
|
| 66 | + print(' '*2 + f'part-{part}') |
70 | 67 | for _, func in list(filter(lambda x: x[0].endswith(f'part{part}'), funcs)):
|
71 |
| - print(' '*2 + f'{day_module.__name__}.{func.__name__}: ', end='') |
| 68 | + output, tit = None, -1 |
72 | 69 | try:
|
73 |
| - output, tit, time = self._run(func, input_data) |
74 |
| - print(output) |
75 |
| - print(' '*4 + '\033[90m'+f'(100, 1): ({tit:f} sec, {time:f} sec)', '\033[0m') |
76 |
| - except BaseException: |
77 |
| - print_exc() |
78 |
| - print() |
| 70 | + output, tit = self._run(func, input_data) |
| 71 | + except BaseException as e: |
| 72 | + output = e |
| 73 | + print(' '*4+f'ƒ {func.__name__}',) |
| 74 | + print(' '*6+'\033[90m'+f'{tit:f}'+'\033[0m', output) |
| 75 | + |
| 76 | + print() |
79 | 77 |
|
80 | 78 | @perf
|
81 | 79 | def _run(self, module, input_data):
|
|
0 commit comments