-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmarks.py
66 lines (51 loc) · 1.93 KB
/
benchmarks.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
from genutility.bench import MeasureMemory
from genutility.time import PrintStatementTime
from nltk.corpus import words
from fuzzycollections import BkCollection, LinearCollection, SymmetricDeletesCollection
w = words.words()
"""
LinearCollection uses 2.040 MiB of memory
LinearCollection init took 0.014999999897554517s
LinearCollection query took 224.71900000004098s
BkCollection uses 67.611 MiB of memory
BkCollection init took 6.187000000150874s
BkCollection query took 31.016000000061467s
SymmetricDeletesCollection uses 688.946 MiB of memory
SymmetricDeletesCollection init took 24.625s
SymmetricDeletesCollection query took 0.0470000000204891s
"""
def asd_1(num):
with PrintStatementTime("LinearCollection init took {delta}s"):
with MeasureMemory() as m:
a = LinearCollection("levenshtein")
a.extend(w)
m.print("LinearCollection")
with PrintStatementTime("LinearCollection query took {delta}"):
for _i in range(num):
res = a.find("horible", 1)
assert res == [(1, "horrible")]
def asd_2(num):
with PrintStatementTime("BkCollection init took {delta}"):
with MeasureMemory() as m:
a = BkCollection("levenshtein")
a.extend(w)
m.print("BkCollection")
with PrintStatementTime("BkCollection query took {delta}"):
for _i in range(num):
res = a.find("horible", 1)
assert res == [(1, "horrible")]
def asd_3(num):
with PrintStatementTime("SymmetricDeletesCollection init took {delta}"):
with MeasureMemory() as m:
a = SymmetricDeletesCollection(max_distance=1)
a.extend(w)
m.print("SymmetricDeletesCollection")
with PrintStatementTime("SymmetricDeletesCollection query took {delta}"):
for _i in range(num):
res = a.find("horible")
assert res == ["horrible"]
if __name__ == "__main__":
TOTAL = 1000
asd_1(TOTAL)
asd_2(TOTAL)
asd_3(TOTAL)