Skip to content

Instantly share code, notes, and snippets.

Created Dec 1, 2020
What would you like to do?
import time
import functools
def timer(func):
"""Print the runtime of the decorated functions
func ([function]): [Will be the function to be decorated - this function should only be used as a decorator]
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