From 958dd2bf2404b5a647e0c94ebba15bfc4c387cd9 Mon Sep 17 00:00:00 2001 From: Peter Sharpe Date: Fri, 22 Dec 2023 11:05:10 +0100 Subject: [PATCH] docs --- aerosandbox/tools/code_benchmarking.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/aerosandbox/tools/code_benchmarking.py b/aerosandbox/tools/code_benchmarking.py index 8a5d866b..bc133b85 100644 --- a/aerosandbox/tools/code_benchmarking.py +++ b/aerosandbox/tools/code_benchmarking.py @@ -12,9 +12,25 @@ class Timer(object): Results are printed to stdout. You can access the runtime (in seconds) directly with: - with Timer("My timer") as t: - # Do stuff - print(t.runtime) + >>> with Timer("My timer") as t: + >>> # Do stuff + >>> print(t.runtime) # You can dynamically access the runtime of any completed Timer, if desired + + Nested timers are also supported. For example, this code: + >>> with Timer("a"): + >>> with Timer("b"): + >>> with Timer("c"): + >>> f() + + yields the following console output: + + [a] Timing... + [b] Timing... + [c] Timing... + [c] Elapsed: 100 msec + [b] Elapsed: 100 msec + [a] Elapsed: 100 msec + """ number_running: int = 0 # The number of Timers currently running