import time
from functools import lru_cache
def calculate_time(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print(end_time - start_time)
return result
return wrapper
def fib(n):
if n == 0 or n == 1:
return 1
return fib(n - 1) + fib(n - 2)
@calculate_time
@lru_cache
def call_fib(n):
return fib(n)
print(call_fib(36))
print(call_fib(36))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter