4 from typing import Callable
9 A stopwatch to time how long something takes (walltime).
13 with timer.Timer() as t:
17 print(f'That took {walltime} seconds.')
20 def __init__(self) -> None:
24 def __enter__(self) -> Callable[[], float]:
25 """Returns a functor that, when called, returns the walltime of the
28 self.start = time.perf_counter()
30 return lambda: self.end - self.start
32 def __exit__(self, *args) -> bool:
33 self.end = time.perf_counter()
34 return None # don't suppress exceptions