This commit is contained in:
Zironic 2026-08-15 07:47:18 +02:00 committed by GitHub
commit 32cb80e688
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

13
tests/test_timer.py Normal file
View File

@ -0,0 +1,13 @@
from toolkit.timer import Timer
def test_print_ignores_cancelled_timer_without_samples():
timer = Timer()
printed_timings = []
timer.add_after_print_hook(printed_timings.append)
timer.start("cancelled")
timer.cancel("cancelled")
timer.print()
assert printed_timings == [{}]

View File

@ -48,6 +48,8 @@ class Timer:
timing_dict = {}
# sort by longest at top
for timer_name, timings in sorted(self.timers.items(), key=lambda x: sum(x[1]), reverse=True):
if not timings:
continue
avg_time = sum(timings) / len(timings)
if not is_ui: