from time import clock
from parse.string import *
from parse.regular import *
import thread
if (__name__ == '__main__'):
asd = []
fi = open('rus.txt','r').readlines()
print 'words:',len(fi)
def one():
global fi, count_thread, asd
while len(fi) > 0:
stroka = fi.pop()
if sim2(stroka):
asd.append(stroka)
count_thread -= 1
count_thread = 0
start = clock() #---------------
for i in xrange(0, 5):
count_thread += 1
thread.start_new_thread(one,())
while count_thread > 0:
pass
end = clock() #---------------
print('one - %1.10f Sec threaded' % (end - start))
def two():
global fi
asd = filter(sim2,fi)
start = clock()
two()
end = clock()
print('two - %1.10f Sec' % (end - start))
def tree():
global fi
while len(fi) > 0:
stroka = fi.pop()
if sim2(stroka):
asd.append(stroka)
start = clock()
tree()
end = clock()
print('tree - %1.10f Sec' % (end - start))
def sim2(stroka):
stroka = stroka[:-1]
if stroka != stroka[::-1]:
return 0
return 1
words: 733967
one - 1.7641071700 Sec threaded
two - 0.0000057968 Sec
tree - 0.0000029333 Sec
>>>
Почему one() работает медленней всего?
Почему two() работает медленней tree()?
И почему иногда выходит “Unhandled exception in thread started by <адресс какойто функции>”?