from functools import cache
import time
@cache
def fib_c(n):
if n <= 1: return n
return fib_c(n-1) + fib_c(n-2)
def fib_n(n):
if n <= 1: return n
return fib_n(n-1) + fib_n(n-2)
def fib_tr(n, a=0, b=1):
if n < 1: return a
return fib_tr(n-1, b, a+b)
def gotimer(f, n):
start = time.time()
f(n)
end = time.time()
print(end - start)
n = 350
# gotimer(fib_n, n)
gotimer(fib_c, n)
gotimer(fib_tr, n)
To embed this project on your website, copy the following code and paste it into your website's HTML: