-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
26 lines (23 loc) · 672 Bytes
/
test.py
File metadata and controls
26 lines (23 loc) · 672 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from lru_cache.lru_cache import SelectiveLRUCache
import cProfile
@SelectiveLRUCache(parameters=lambda x:(x[0],), maxsize=None)
def FibonacciWithLRU(n, cntr):
if n<0:
print("Incorrect input")
elif n==0:
return 0
elif n==1:
return 1
else:
return FibonacciWithLRU(n-1, cntr)+FibonacciWithLRU(n-2, cntr)
def Fibonacci(n, cntr):
if n<0:
print("Incorrect input")
elif n==0:
return 0
elif n==1:
return 1
else:
return Fibonacci(n-1, cntr)+Fibonacci(n-2, cntr)
cProfile.runctx("Fibonacci(40, 0)", globals(), locals())
cProfile.runctx("FibonacciWithLRU(40, 0)", globals(), locals())