-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
70 lines (50 loc) · 1.56 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from timeit import timeit
import cProfile
import re
import info
import textTools as tt
import tauntbot
import stats
strings = ['a', 'b', 'Zażółć gęślą jaźń', 'jeszcze', 'be', 'tak jak pan jezus powiedzial',
'dobry wieczor', 'ąśćóódsf', 'ąśćóódsfafwepiscvkmmkvpwoekapdvasdvas', 'będziemy jechac'
]
# original function before 2020-01
def check(t, s):
return re.search(r'\b'+s, t)
# function with compiled regex
def check_comp(t, s):
return s.search(t)
# more efficient without regex
def check_dumb(t, s):
if t.startswith(s) or ' '+s in t:
return True
return False
def find(s, f):
if f is check_comp:
s = re.compile(r'\b'+s)
partMatches = set()
for index, taunt in enumerate(info.taunts[1:], start=1):
for key in ['name', 'content', 'category', 'source']:
field = tt.clean(taunt[key])
if f(field, s):
partMatches.add(index)
break
return partMatches
def test_find():
def test(f):
for s in strings: f(s)
for f in (check, check_comp, check_dumb):
print(timeit(lambda: test(f), number=100))
def test2():
for s in strings:
print(timeit(lambda: tauntbot.compare(s), number=100))
def profile():
cProfile.run('test2()', sort='cumtime')
def test_clean():
for s in strings:
for f in (tt.clean, tt.clean_legacy):
print(timeit(lambda: f(s), number=50000))
def test_queries():
queries = [q for q in stats.query_log() if q]
for query in queries:
tauntbot.compare(query)