16 lines
415 B
Python
Raw Normal View History

2024-11-23 19:56:52 +01:00
import time
class Duration:
def __init__(self, description):
self.description = description
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.end = time.time()
self.duration = self.end - self.start
print(self.description,end=" ")
print("took {} seconds.".format(self.duration))