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

John Machin sjmachin at lexicon.net
Mon Oct 2 03:35:31 EDT 2006


Fredrik Lundh wrote:

>
> You should also benchmark this against code that uses the ordinary
> append/join pattern.  (you've posted conflicting benchmarks for 2.5,
> but if I'm trusting the benchmarks that looks more reasonable, the
> standard implementation pattern is still around 10 times faster than
> your approach).
>

And the OP might like to go a bit further, and as well as benchmarking
this style:
    array = []
    array.append("aaa")
    array.append("bbb")
    etc
try benchmarking this ... well "style" may not be the appropriate word
:-)
    array = []
    arrapp = array.append
    arrapp('aaa')
    arrapp('bbb')
    etc

Cheers,
John




More information about the Python-list mailing list