mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add logged_duration context manager for profiling.
This commit is contained in:
13
game/profiling.py
Normal file
13
game/profiling.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import logging
|
||||
import timeit
|
||||
from contextlib import contextmanager
|
||||
from datetime import timedelta
|
||||
from typing import Iterator
|
||||
|
||||
|
||||
@contextmanager
|
||||
def logged_duration(event: str) -> Iterator[None]:
|
||||
start = timeit.default_timer()
|
||||
yield
|
||||
end = timeit.default_timer()
|
||||
logging.debug("%s took %s", event, timedelta(seconds=end - start))
|
||||
Reference in New Issue
Block a user