[Python-ideas] Create a StringBuilder class and use it everywhere
k.bx at ya.ru
Thu Aug 25 11:56:42 CEST 2011
25.08.2011, 12:53, "Carl Matthew Johnson" <cmjohnson.mailinglist at gmail.com>:
> Interesting semantics…
> 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
> Python-ideas mailing list
> Python-ideas at python.org
I use cpython 2.7 that comes with Ubuntu Natty with latest updates.
More information about the Python-ideas