Skip to content

Instantly share code, notes, and snippets.

@norbertparti
Created March 3, 2021 09:54
Show Gist options
  • Save norbertparti/41023394350c47411f5694143b71a81d to your computer and use it in GitHub Desktop.
Save norbertparti/41023394350c47411f5694143b71a81d to your computer and use it in GitHub Desktop.
Python Timer Decorator
"""Build the timefunc decorator."""
import time
import functools
def timefunc(func):
"""timefunc's doc"""
@functools.wraps(func)
def time_closure(*args, **kwargs):
"""time_wrapper's doc string"""
start = time.perf_counter()
result = func(*args, **kwargs)
time_elapsed = time.perf_counter() - start
print(f"Function: {func.__name__}, Time: {time_elapsed}")
return result
return time_closure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment