Files
bugsink/performance/context_managers.py
Klaas van Schelven a24c295535 Forgotten file added
2024-05-22 20:57:16 +02:00

14 lines
244 B
Python

import time
from contextlib import contextmanager
@contextmanager
def time_to_logger(logger, msg):
t0 = time.time()
try:
yield
finally:
took = (time.time() - t0) * 1000
logger.info(f"{took:6.2f}ms {msg}")