forked from bellwether/minerva
21 lines
417 B
Python
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")
|
|
|