-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
56 lines (50 loc) · 1.61 KB
/
test.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
import time
import numpy as np
import fast_edit_distance
import Levenshtein
def random_seq_generator():
while True:
yield ''.join(np.random.choice(['A', 'G', "C", 'T'], size=np.random.randint(20,50)))
rand_seq = random_seq_generator()
print("Runtime test no max ed cutoff(1_000_000 iteration):")
np.random.seed(2023)
start_time = time.time()
a = next(rand_seq)
b = next(rand_seq)
l_ed = []
for i in range(1_000_000):
l_ed.append(Levenshtein.distance(a, b))
end_time = time.time()
print(f"Levenshtein.distance: {end_time - start_time:.2f}s" )
np.random.seed(2023)
start_time = time.time()
a = next(rand_seq)
b = next(rand_seq)
fast_ed = []
for i in range(1_000_000):
fast_ed.append(fast_edit_distance.edit_distance(a, b))
end_time = time.time()
print(f"fast_edit_distance.edit_distance: {end_time - start_time:.2f}s")
print("Result consistant?")
print("No!" if any(np.array(l_ed) != np.array(fast_ed)) else "Yes!")
print("Runtime test with max ed cutoff 1 (1_000_000 iteration):")
np.random.seed(2023)
start_time = time.time()
a = next(rand_seq)
b = next(rand_seq)
l_ed = []
for i in range(1_000_000):
l_ed.append(Levenshtein.distance(a, b, score_cutoff=1))
end_time = time.time()
print(f"Levenshtein.distance: {end_time - start_time:.2f}s" )
np.random.seed(2023)
start_time = time.time()
a = next(rand_seq)
b = next(rand_seq)
fast_ed = []
for i in range(1_000_000):
fast_ed.append(fast_edit_distance.edit_distance(a, b, 1))
end_time = time.time()
print(f"fast_edit_distance.edit_distance: {end_time - start_time:.2f}s")
print("Result consistant?")
print("No!" if any(np.array(l_ed) != np.array(fast_ed)) else "Yes!")