Last active
April 8, 2024 10:14
-
-
Save DougAF/ef88f89d1d99763bb05afd81285ef233 to your computer and use it in GitHub Desktop.
From Edwards joblib repo - more useful timing function with closure
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
import time
import functools
def timefunc(func):
"""timefunc's doc"""