[Twisted-Python] twisted socksv4 proxy

Andrew Bennetts andrew-twisted at puzzling.org
Thu Sep 25 00:10:56 EDT 2003


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?

-Andrew.





More information about the Twisted-Python mailing list