neaten output on timeit runs
This commit is contained in:
parent
8278b91e19
commit
1e9844e79c
@ -1,8 +1,19 @@
|
|||||||
def printSolution(day, part, solution, test=None, test_case=0):
|
def printSolution(day, part, solution, test=None, test_case=0, exec_time=None):
|
||||||
|
if exec_time is None:
|
||||||
|
time_output = ""
|
||||||
|
else:
|
||||||
|
units = ['s', 'ms', 'μs', 'ns']
|
||||||
|
unit = 0
|
||||||
|
while exec_time < 1:
|
||||||
|
exec_time *= 1000
|
||||||
|
unit += 1
|
||||||
|
|
||||||
|
time_output = " (Average run time: %1.2f%s)" % (exec_time, units[unit])
|
||||||
|
|
||||||
if test is not None:
|
if test is not None:
|
||||||
print(
|
print(
|
||||||
"(TEST case%d/day%d/part%d) -- got '%s' -- expected '%s' -> %s"
|
"(TEST case%d/day%d/part%d) -- got '%s' -- expected '%s' -> %s"
|
||||||
% (test_case, day, part, solution, test, "correct" if test == solution else "WRONG")
|
% (test_case, day, part, solution, test, "correct" if test == solution else "WRONG")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print("Solution to day %s, part %s: %s" % (day, part, solution))
|
print("Solution to day %s, part %s: %s%s" % (day, part, solution, time_output))
|
||||||
|
|||||||
4
main.py
4
main.py
@ -62,7 +62,7 @@ for lib in sorted(imported):
|
|||||||
globals=globals(),
|
globals=globals(),
|
||||||
number=flags.timeit_number
|
number=flags.timeit_number
|
||||||
) / flags.timeit_number
|
) / flags.timeit_number
|
||||||
aoclib.print_execution_time(day, 1, exec_time)
|
aoclib.printSolution(day, 1, day_class.part1(), exec_time=exec_time)
|
||||||
|
|
||||||
if not flags.part or flags.part == 2:
|
if not flags.part or flags.part == 2:
|
||||||
if not flags.timeit:
|
if not flags.timeit:
|
||||||
@ -76,4 +76,4 @@ for lib in sorted(imported):
|
|||||||
globals=globals(),
|
globals=globals(),
|
||||||
number=flags.timeit_number
|
number=flags.timeit_number
|
||||||
) / flags.timeit_number
|
) / flags.timeit_number
|
||||||
aoclib.print_execution_time(day, 2, exec_time)
|
aoclib.printSolution(day, 2, day_class.part2(), exec_time=exec_time)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user