-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_fib.py
42 lines (33 loc) · 1023 Bytes
/
bench_fib.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from logicpy import *
from logicpy.core import *
from logicpy.builtin import *
from logicpy.predicate import *
from logicpy.data import *
import time
u, n = Universe().and_namespace()
n.fib[0, 1] = True
n.fib[1, 2] = True
n.fib[_.N, _.Res] = and_(
_.N > 1,
_.N1 << _.N - 1,
_.N2 << _.N - 2,
n.fib(_.N1, _.Res1),
n.fib(_.N2, _.Res2),
_.Res << _.Res1 + _.Res2)
fib = lambda x: {0: 1, 1: 2, 2: 3}.get(x) or fib(x-1) + fib(x-2)
try:
for arg in range(10):
check = fib(arg)
try:
start = time.time()
res = u.simple_query(n.fib(arg, _.X))[0]['X']
end = time.time()
assert check == res, f"{check} != {res}"
print(f"{arg}\t{end - start}")
except Exception as e:
print("\nFAIL --------------------------------------------------")
print(e, "\n")
print(u.simple_query(n.fib(arg, _.X), debug=True))
break
except KeyboardInterrupt:
pass