Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created December 1, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/bb312d167985d9db8c7ea0c0ca01d2f4 to your computer and use it in GitHub Desktop.
Save JeffersGlass/bb312d167985d9db8c7ea0c0ca01d2f4 to your computer and use it in GitHub Desktop.
import time
import functools
def timer(func):
"""Print the runtime of the decorated functions
Args:
func ([function]): [Will be the function to be decorated - this function should only be used as a decorator]
"""
@functools.wraps(func)
def wrapper_timer(*args, **kwargs):
start_time = time.perf_counter()
value = func(*args, **kwargs)
elapsed = time.perf_counter() - start_time
print(f"Function {func.__name__!r} took {elapsed:.6f} seconds to complete.")
return value
return wrapper_timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment