/usr/lib/python2.7/dist-packages/mx/TextTools/mxTextTools/testkj.py is in python-egenix-mxtexttools 3.2.8-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 | #! /usr/bin/python
""" Run a few tests using the King James Bible plain text version as
available from:
http://www.gutenberg.org/etext/10
"""
import re, time
from mx import TextTools, Tools
# Location of the text file
KJB = '/tmp/kjv10.txt'
# Iterations to use for benchmarking
COUNT = 100
def search_bench(word, text):
iterations = Tools.trange(COUNT)
print ('Searching for all occurences of %r using ...' % word)
t0 = time.time()
so = TextTools.TextSearch(word)
for i in iterations:
l = so.findall(text)
t1 = time.time()
count = len(l)
print (' - mx.TextSearch.TextSearch().findall(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
t0 = time.time()
so = re.compile(word)
for i in iterations:
l = so.findall(text)
t1 = time.time()
count = len(l)
print (' - re.compile().findall(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
t0 = time.time()
for i in iterations:
count = text.count(word)
t1 = time.time()
print (' - text.count(): %5.3f ms (%i)' %
((t1 - t0) / COUNT * 1000.0, count))
if __name__ == '__main__':
text = open(KJB).read()
search_bench('God', text)
search_bench('Jesus', text)
search_bench('devil', text)
search_bench('love', text)
search_bench('hate', text)
|