forked from szsam/regex-memo-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytest.py
73 lines (59 loc) · 2.24 KB
/
mytest.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
import re
#import concurrent.futures
import multiprocessing
import math
import json
import argparse
#REGEX = "(" + "a"*7 + "|" + "a"*9 + ")*"
#RUNLEN = [63, 1]
#REGEX = "(aaa)*(a|aa)(aa)*"
#RUNLEN = [3,6]
def do_test(regex, start, end, runlen):
#print("args:", regex, start, end, runlen)
patt = re.compile(regex, runlen=runlen)
results = []
for l in range(start, end):
input_str = "a"*l + "z"
m = patt.fullmatch(input_str)
results.append(patt.memostat)
return results
def main():
parser = argparse.ArgumentParser()
parser.add_argument("filename", type=str)
args = parser.parse_args()
#regexes = ["(aaa)*?(aaaa)*"]
#runlens = [[3, 4]]
regexes, runlens = [], []
with open(args.filename) as f:
#regexes = [line.rstrip() for line in f]
for line in f:
line = line.split(maxsplit=1)
regex, runlen = line[0], line[1].rstrip()
runlen = json.loads(runlen)
regexes.append(regex)
runlens.append(runlen)
#print(regexes, runlens)
#regexes = regexes[:100]
#runlens = runlens[:100]
#with concurrent.futures.ProcessPoolExecutor() as executor:
num_cores = 64
N = 10000
print("N=1:{}".format(N))
for regex, runlen in zip(regexes, runlens):
print(regex, runlen)
with multiprocessing.Pool(num_cores) as pool:
args = [(regex, math.floor(N*math.sqrt(k/num_cores)),
math.floor(N*math.sqrt((k+1)/num_cores)),
runlen) for k in range(num_cores)]
results = pool.starmap(do_test, args)
results = [item for sublist in results for item in sublist]
#[print(item) for item in results]
lst_final_runs = [item['final_n_runs'] for item in results]
lst_max_runs = [item['max_n_runs'] for item in results]
final_runs_bound = [max(v) for v in zip(*lst_final_runs)]
max_runs_bound = [max(v) for v in zip(*lst_max_runs)]
for i,(r,f,m) in enumerate(zip(runlen, final_runs_bound, max_runs_bound)):
print("[vertex {}] runlen: {}, final_n_runs_bound: {}, max_n_runs_bound: {}".format(
i, r, f, m))
if __name__ == "__main__":
main()