Daevaornспасибо за поправку, написал следующий инструмент для более правильных замеров:
from time import clock
import gc
from cStringIO import StringIO
import psyco
def getTime(f, it):
start = clock()
for i in it:
f()
end = clock()
return end - start;
def testIt(f, name, reps = 10):
gcState = gc.isenabled
gc.enable()
it = xrange(reps)
psyco.bind(f)
time1 = getTime(f, it) / reps
psyco.unbind(f)
time2 = getTime(f, it) / reps
gc.disable()
psyco.bind(f)
time3 = getTime(f, it) / reps
psyco.unbind(f)
time4 = getTime(f, it) / reps
if gcState:
gc.enable()
return '%s\t%.5f\t%.5f\t%.5f\t%.5f\tsec/repeat in %d repeats' % (name, time1, time2, time3, time4, reps)
def compareFuncs(funcList, reps = 10):
result = StringIO()
result.write('\tpsy&gc\tgc\t\tpsyco\tclean\n')
for f in funcList:
result.write(testIt(f, str(f).split()[1], reps))
result.write('\n')
result.seek(0)
return result.read()
Немного поправил, теперь это полный текст модуля для сравнения