Can you make this faster?
alejandro david weil
aweil at mail.ru
Sun Jun 27 17:51:20 EDT 2004
>
> But, anyway, the problem seems to be the:
> f2 += str(len(arg))
> line.
>
> If you take it off, you'll see that time reduces to half!
> Why? How to fix?
> Don't know! :-(
For example, this seems to be "better":
typedic = {
types.StringType : 's',
types.IntType: 'i',
types.LongType: 'q',
types.BooleanType: 'c',
types.FloatType:'d'}
slen = {}
for i in xrange(256):
slen[i]=str(i)
def myfmtstring(args):
global typedic, slen
f2 = '<'
t = None
for arg in args:
t = type(arg)
if t == types.StringType:
try:
f2+=slen[len(arg)]
except:
print 'aca'
f2 += str(len(arg))
try:
f2 += typedic[t]
except: #check the exception here!
raise Exception("Can't pack argument of type %s!" % t)
return f2+'\0'
--
+ There is no dark side of the moon really. Matter of fact it's all dark.
More information about the Python-list
mailing list