Created
April 8, 2023 11:47
-
-
Save bbelderbos/2ec6fba103ce9ce079ea1987e367e0a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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