Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created April 8, 2023 11:47
Show Gist options
  • Save bbelderbos/2ec6fba103ce9ce079ea1987e367e0a1 to your computer and use it in GitHub Desktop.
Save bbelderbos/2ec6fba103ce9ce079ea1987e367e0a1 to your computer and use it in GitHub Desktop.
from time import time, sleep
from functools import wraps
def timeit(func):
@wraps(func)
def wrapped(*arg, **kwargs):
start = time()
result = func(*arg, **kwargs)
end = time()
print(f"{func.__name__} took {int(end - start)} seconds")
return result
return wrapped
@timeit
def myfunc(time_to_sleep: int) -> None:
"""This function does some work"""
sleep(time_to_sleep)
@timeit
def myfunc2():
return 1
myfunc(1)
ret = myfunc2()
print("myfunc2 returned", ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment