Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save normanlmfung/1665931c2eb94f2e02756a0dfd0f849a to your computer and use it in GitHub Desktop.
Save normanlmfung/1665931c2eb94f2e02756a0dfd0f849a to your computer and use it in GitHub Desktop.
python_syntax_decorator_timer
# 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