Skip to content

Instantly share code, notes, and snippets.

@alkasm
Forked from bradmontgomery/LICENSE.txt
Last active July 29, 2019 23:17
Show Gist options
  • Save alkasm/81d3153fd301e5e6be5b22d451405152 to your computer and use it in GitHub Desktop.
Save alkasm/81d3153fd301e5e6be5b22d451405152 to your computer and use it in GitHub Desktop.
A python decorator that logs execution time.
from functools import wraps
import logging
import time
logger = logging.getLogger(__name__)
def timed(func):
"""This decoratorlogs the execution time for the decorated function."""
@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
logger.debug(
"{} took {:03d} ms".format(func.__name__, int(1000 * (end - start)))
)
return result
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment