Can you make this faster?
alejandro david weil
aweil at mail.ru
Mon Jun 28 00:05:50 EDT 2004
On Sun June 27 2004 21:18, Christopher T King wrote:
> If neither of the above apply to you, or give you the speedup you need,
> try using the Psyco JIT compiler to compile the function. After installing
> Psyco, all you need to do is to 'import psyco' and 'psyco.bind(fmtstring)'
> at the top of the file your function resides in.
I had never tried psyco, so I did it:
Some more stats (arguments given: [ 'hola','que','tal',324,454,False] )
no psyco | psyco
original code 4.664s | 2.132s
modified ver 2.222s | 0.840s
print 4.66 / 0.84
-> 5.54..
Not yet 7x faster :-( but 5.5 is very good i think.
modified version:
slen = []
for i in xrange(256):
slen.append(str(i)+'s'
typedic = {
types.IntType: 'i',
types.LongType: 'q',
types.BooleanType: 'c',
types.FloatType:'d'}
def myfmtstring(args):
global typedic, slen
flen = slen
ftypedic = typedic
f2 = '<'
st = types.StringType
for arg in args:
t = type(arg)
if t == st:
l = len(arg)
if l<256:
f2+=flen[l]
else:
f2+=str(l)+'s'
else:
try:
f2+=ftypedic[t]
except:
raise Exception("Can't pack argument of type %s!" % t)
return f2+'\0'
Saludos,
alejandro
--
+ There is no dark side of the moon really. Matter of fact it's all dark.
More information about the Python-list
mailing list