[Python-Dev] Usage of += on strings in loops in stdlib (original) (raw)

Lennart Regebro regebro at gmail.com
Wed Feb 13 21:40:35 CET 2013


On Wed, Feb 13, 2013 at 4:02 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote:

2013/2/13 Lennart Regebro <regebro at gmail.com>

On Wed, Feb 13, 2013 at 3:27 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com> wrote: > Yes, it's jitted. Admittedly, I have no idea in which cases the JIT kicks in, and what I should do to make that happen to make sure I have the best possible real-life test cases. PyPy JIT kicks in only after 1000 iterations.

Actually, my test code mixed iterations and string length up when printing the results, so the tests I showed was not 100 iterations with 10.000 long string, but 10.000 iterations with 100 long strings.

No matter what the iteration/string length is .format() is the slowest or second slowest of all string concatenation methods I've tried and '%s%s' % just marginally faster. This both on PyPy and CPython and irrespective of string length.

I'll stick my neck out and say that using formatting for concatenation is probably an anti-pattern.

//Lennart



More information about the Python-Dev mailing list