-
-
Save JeffersGlass/bb312d167985d9db8c7ea0c0ca01d2f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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