Skip to content

Instantly share code, notes, and snippets.

@DougAF
Last active April 8, 2024 10:14
Show Gist options
  • Save DougAF/ef88f89d1d99763bb05afd81285ef233 to your computer and use it in GitHub Desktop.
Save DougAF/ef88f89d1d99763bb05afd81285ef233 to your computer and use it in GitHub Desktop.
From Edwards joblib repo - more useful timing function with closure
"""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
@DougAF
Copy link
Author

DougAF commented Feb 21, 2021

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