Created
March 3, 2021 09:54
-
-
Save norbertparti/41023394350c47411f5694143b71a81d to your computer and use it in GitHub Desktop.
Python Timer Decorator
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
"""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