-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_generator.py
executable file
·58 lines (52 loc) · 1.74 KB
/
test_generator.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
#!/usr/bin/python
import sys
import random
import subprocess
from datetime import datetime
test_dimension = [
(100, 100),
(1000, 1000),
(10000, 10000),
(100, 100000),
(100000, 100),
(80000, 800000),
(800000, 800000),
]
if len(sys.argv) < 3 or sys.argv[2] != "onlyrun":
alphabet = "".join(set(sys.argv[1]))
for (len1, len2) in test_dimension:
first = [random.choice(alphabet) for _ in range(int(len1))]
second = [random.choice(alphabet) for _ in range(int(len2))]
with open(f"input{len1}X{len2}.txt", "w") as f:
f.write(f"{str(''.join(first))} {str(''.join(second))}")
for (len1, len2) in test_dimension:
for num_threads in [2, 4, 8, 16]:
outputs = []
subprocess.run(
["gcc", "-fopenmp", "edit_distance.c", "-o", "ed"]
) # gcc -fopenmp edit_distance.c -o ed
print(f"running {len1} {len2} \n")
outputs.append(
subprocess.run(
[
"./ed",
f"{len1}",
f"{len2}",
f"input{len1}X{len2}.txt",
f"{num_threads}",
],
capture_output=True,
text=True,
).stdout
) # ./ed $1 $2 $3
print(str(outputs[-1]))
with open("test_results.txt", "a") as f:
now = datetime.now()
f.write("\n")
f.write(f"-----------------------{now}----------------------- \n")
f.write(
f"-----------------------{num_threads} {len1} {len2} ----------------------- \n"
)
f.writelines(outputs)
f.write(f"\\-----------------------{now}-----------------------\\")
f.write("\n")