Write a Timer class usable as a context manager.
with Timer() as t:
do_work()
print(t.elapsed)
__enter__ records the start and returns the timer itself - without that return, as t binds None.
__exit__ sets elapsed to the seconds taken. It must run even when the block raises, and must not swallow the exception: return a falsy value so the error still propagates.
Use time.perf_counter().