from functools import lru_cache, partial import timeit @lru_cache(maxsize = 128) def fibonacci(n): if n == 0: return 0 elif n == 1: return 1 return fibonacci(n - 1) + fibonacci(n - 2) #the first time execution_time = timeit.Timer(partial(fibonacci, 50)).timeit(1) print(execution_time) #the second time execution_time = timeit.Timer(partial(fibonacci, 50 )).timeit(1) print(execution_time)