From c235bbebdaf6e62c760ec1a277eed44a0ad2b698 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Tue, 18 Apr 2023 17:13:44 +0200 Subject: [PATCH] tools: Sort timer results by time. --- src/tools.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/tools.py b/src/tools.py index b53c6f6f..eee57547 100644 --- a/src/tools.py +++ b/src/tools.py @@ -24,8 +24,19 @@ def display_timers(): global _calls print(" +---------------------------------------------------------Timers--+") - for func in _timers: - print(f" | {func:<32} | {_timers[func]:>10.6f} sec | {_calls[func]:>5} calls |") + + lst = sorted( + map( + lambda f: (f, _timers[f], _calls[f]), + _timers + ), + key=lambda f: f[1], + reverse = True + ) + + for func, time, calls in lst: + print(f" | {func:<32} | {time:>10.6f} sec | {calls:>5} calls |") + print(" +-----------------------------------------------------------------+") def timer(func): -- GitLab