Created
March 30, 2024 22:30
-
-
Save normanlmfung/1665931c2eb94f2e02756a0dfd0f849a to your computer and use it in GitHub Desktop.
python_syntax_decorator_timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# timer (Simply log the duration of time the wrapped method took). Can also be extended to filter/modify parameters. | |
def timer(method): | |
def timed(*args, **kw): | |
start = time.time() | |
result = method(*args, **kw) | |
elapsed = (time.time() - start) * 1000 | |
logger.info(f'@timer {method.__qualname__} returned in {elapsed} ms. {args_}') | |
return result | |
return timed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment