From 1e9844e79cc518a63098b893b4797e293e9ccf4f Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 21 Nov 2021 13:18:06 +0100 Subject: [PATCH] neaten output on timeit runs --- aoclib/output.py | 15 +++++++++++++-- main.py | 4 ++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aoclib/output.py b/aoclib/output.py index 06dc6b0..faa377b 100644 --- a/aoclib/output.py +++ b/aoclib/output.py @@ -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: print( "(TEST case%d/day%d/part%d) -- got '%s' -- expected '%s' -> %s" % (test_case, day, part, solution, test, "correct" if test == solution else "WRONG") ) 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)) diff --git a/main.py b/main.py index a2b9289..88c1f68 100644 --- a/main.py +++ b/main.py @@ -62,7 +62,7 @@ for lib in sorted(imported): globals=globals(), 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.timeit: @@ -76,4 +76,4 @@ for lib in sorted(imported): globals=globals(), 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)