Last active
July 8, 2021 19:07
-
-
Save deadPix3l/7925054246cb19611fb5de924e7498b2 to your computer and use it in GitHub Desktop.
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
from timeit import default_timer as timer | |
from datetime import timedelta | |
from functools import cache | |
def timefunc(f): | |
def wrapper(*a, **kw): | |
start = timer() | |
retval = f(*a, **kw) | |
end = timer() | |
print(f"{a} => {retval} ({timedelta(seconds=end-start)} elapsed)") | |
print(f"") | |
return retval | |
return wrapper | |
@timefunc | |
def finalfib(n): | |
return fib(n) | |
@cache #this line removed for uncached version. no other code changes | |
def fib(n): | |
if n<=1: return 1 | |
return fib(n-1) + fib(n-2) | |
for i in range(3): | |
finalfib(40) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment