[Python-ideas] Create a StringBuilder class and use it everywhere
Carl Matthew Johnson
cmjohnson.mailinglist at gmail.com
Thu Aug 25 11:53:49 CEST 2011
What version of Python were you using? The current documentation has this to say:
• CPython implementation detail: If s and t are both strings, some Python implementations such as CPython can usually perform an in-place optimization for assignments of the form s = s + t or s += t. When applicable, this optimization makes quadratic run-time much less likely. This optimization is both version and implementation dependent. For performance sensitive code, it is preferable to use thestr.join() method which assures consistent linear concatenation performance across versions and implementations.
Changed in version 2.4: Formerly, string concatenation never occurred in-place.
It's my understanding that the naïve approach should now have performance comparable to the "proper" list append technique as long as you use CPython >2.4.
-- Carl Johnson
More information about the Python-ideas