forked from karmaresearch/Laser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.py
executable file
·117 lines (110 loc) · 3.84 KB
/
bench.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import sys
import json
import timeit
import time
from stream.file_stream import FileStream
from evalunit.program import Program
OUTPUT = False
# OUTPUT = True
def get_rules(prog_name, win_size):
rules = []
if (prog_name == "ATOM"):
rules = [
"a(X1, X2) :- p(X1, X2)",
]
elif (prog_name == "CONJ2"):
rules = [
"a(X1,X2) :- p(X1, X2) and q(X1, X2)",
]
elif (prog_name == "CONJ4"):
rules = [
"a(X1,X2) :- p(X1, X2) and q(X1, X2) and p(X1, X2) and q(X1, X2)",
]
elif (prog_name == "CONJ8"):
rules = [
"a(X1,X2) :- p(X1, X2) and q(X1, X2) and p(X1, X2) and q(X1, X2) and p(X1, X2) and q(X1, X2) and p(X1, X2) and q(X1, X2) ",
]
elif (prog_name == "CONJNOCOM"):
rules = [
"a(X1,X2,X3,X4) :- p(X1, X2) and q(X3, X4)",
]
elif (prog_name == "CONJTRAN"):
rules = [
"p(X1,X3) :- p(X1, X2) and p(X2, X3)",
]
elif (prog_name == "DIA"):
rules = [
"".join(["a(X1, X2) :- time_win(", win_size, ",0,1,diamond(p(X1, X2)))"]),
]
elif (prog_name == "BOX"):
rules = [
"".join(["a(X1, X2) :- time_win(", win_size, ",0,1,box(p(X1, X2)))"]),
]
elif (prog_name == "ALGB"):
rules = [
"a(Y) :- p(X1, X2) and MATH(+,Y,X1,99)",
]
elif (prog_name == "COND"):
rules = [
"a(X1, X2) :- p(X1, X2) and COMP(>=,X1,X2)",
"b(X1, X2) :- p(X1, X2) and COMP(<=,X1,X2)",
"c(X1, X2) :- p(X1, X2) and COMP(>,X1,X2)",
"d(X1, X2) :- p(X1, X2) and COMP(<,X1,X2)",
]
elif (prog_name == "PROB"):
rules = [
"".join(["warn(X1, X2) :- time_win(", win_size, ",0,1,diamond(p(X1, X2)))"]),
"".join(["error(X1, X2) :- time_win(", win_size, ",0,1,box(q(X1, X2)))"]),
"prob(X1, X2) :- error(X1, X2) and warn(X1, X2)",
]
elif (prog_name == "SNOW"):
rules = [
"".join(["snow(X1, X2) :- time_win(", win_size, \
",0,1,diamond(p(X1, X2))) and time_win(",\
win_size, ",0,1,box(q(X1, X2)))"]),
]
elif (prog_name == "TRFC"):
rules = [
"".join(["warning(X1, X2) :- time_win(", win_size, ",0,1,diamond(p(X1, X2)))"]),
"".join(["stop(X1, X2) :- time_win(", win_size, ",0,1,box(q(X1, X2)))"]),
"jam(X1, X2) :- p(X1, X2) and q(X1, X2)",
]
return rules
def run(rules, stream_file):
s = FileStream(stream_file)
timeline = s.getTimeLine()
end_time = timeline["endTime"]
prog = Program(rules, s)
fact_count = 0
conclusion_count = 0
start = time.time()
for t in range(end_time + 1):
res, tuples = prog.evaluate(t)
for key, value in tuples.items():
conclusion_count += len(value)
fact_count += s.getNumberOfTuplesAt(t)
if (OUTPUT):
print(tuples)
end = time.time()
elapsed_secs = end - start
eval_secs = prog.get_eval_secs()
throughput = (fact_count * 1.0) / elapsed_secs
print("Endtime: %d" % end_time)
print("Facts: %d, Conclusions: %d" % (fact_count, conclusion_count))
print("Time: %f seconds" % elapsed_secs )
print("Throughput: %f facts/sec" % throughput )
def main():
if (len(sys.argv) < 4):
print ('Usage: python bench.py program_id win_size stream_file')
else:
prog_name = sys.argv[1]
win_size = sys.argv[2]
stream_path = sys.argv[3]
rules = get_rules(prog_name, win_size)
print("Program: %s, win_size: %s" % (prog_name, win_size))
print("Input: %s" % stream_path)
run(rules, stream_path)
print("************************************************************")
print("")
if __name__ == '__main__':
main()