PATCH: Speed up direct string concatenation by 20+%!

William Heymann kosh at aesaeion.com
Fri Sep 29 11:25:09 EDT 2006


On Friday 29 September 2006 08:34, Larry Hastings wrote:
> It would still blow up if you ran
>   s = ""
>   for i in range(10000000):
>     s = "a" + s


This is a pretty small change but I would suggest xrange instead of range. 
That way you don't allocate that large list just to throw all the items away. 

In this case xrange will probably be faster then range also.



More information about the Python-list mailing list