26 lines
484 B
Python
26 lines
484 B
Python
from functools import lru_cache
|
|
|
|
import functools
|
|
import time
|
|
|
|
def time_calculation(f):
|
|
@functools.wraps(f)
|
|
def wrapper(*args, **kwargs):
|
|
start = time.perf_counter()
|
|
result = f(*args, **kwargs)
|
|
end = time.perf_counter()
|
|
print(f"Dauer: {end-start:.4f} Sekunden")
|
|
return result
|
|
|
|
return wrapper
|
|
|
|
@time_calculation
|
|
@lru_cache(maxsize=None)
|
|
def ways(n):
|
|
if n <= 2:
|
|
return n
|
|
return ways(n-1) + ways(n-2)
|
|
|
|
print(ways(40))
|
|
|