Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass

JeffersGlass/timer.py Secret

Created Dec 1, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.