Skip to content

Instantly share code, notes, and snippets.

@deadPix3l
Last active July 8, 2021 19:07
Show Gist options
  • Save deadPix3l/7925054246cb19611fb5de924e7498b2 to your computer and use it in GitHub Desktop.
Save deadPix3l/7925054246cb19611fb5de924e7498b2 to your computer and use it in GitHub Desktop.
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