[Twisted-Python] twisted socksv4 proxy
Jp Calderone
exarkun at intarweb.us
Thu Sep 25 00:46:16 EDT 2003
On Thu, Sep 25, 2003 at 02:10:56PM +1000, Andrew Bennetts wrote:
> On Wed, Sep 24, 2003 at 06:30:06PM -0400, Bob Ippolito wrote:
> > yay for profiling :)
> >
> > oh wow that's definitely going to be slow:
> > f.write(string.join(map(lambda x:'%02X'%ord(x),p),' ')+' ')
> >
> > It's just that one line of code killing all your performance :) That
> > little loop could (probably) be done MUCH more efficiently by using
> > something like:
> > map('%02X'.__mod__, struct.unpack('B' * len(data), data))
> >
> > instead of doing it 16 at a time with lambda and ord.
>
> Probably just "data.encode('hex')" would be fine?
>
Especially since str.__mod__ is a pretty recent development (ie, not in
2.2).
Or one could ask why exactly the data needs to be hex encoded at all...
Jp
--
"Pascal is Pascal is Pascal is dog meat."
-- M. Devine and P. Larson, Computer Science 340
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030925/885d5bcb/attachment.pgp
More information about the Twisted-Python
mailing list