minerva/minerva/timing.py
2023-10-10 19:24:16 -04:00

21 lines
417 B
Python

import time
# with Timing("my operation"):
# long_operation()
#
# => prints "my operation: 45.234"
class Timing:
def __init__(self, desc):
self.desc = desc
def __enter__(self):
self.start = time.time()
print(self.desc)
return self
def __exit__(self, exception_type, exception_value, exception_traceback):
print(f"\t=> {time.time() - self.start}s")