[Python-Dev] Usage of += on strings in loops in stdlib

Maciej Fijalkowski fijall at gmail.com
Wed Feb 13 00:30:10 CET 2013

On Wed, Feb 13, 2013 at 1:28 AM, Christian Heimes <christian at python.org> wrote:
> Am 12.02.2013 22:32, schrieb Antoine Pitrou:
>> For the record, io.StringIO should be quite fast in 3.3.
>> (except for the method call overhead that Guido is complaining
>> about :-))
> AFAIK it's not the actual *call* of the method that is slow, but rather
> attribute lookup and creation of bound method objects. If speed is of
> the essence, code can cache the method object locally:
> strio = io.StringIO()
> write = strio.write
> for element in elements:
>     write(element)
> result = strio.getvalue()

And this is a great example of muddying code in stdlib for the sake of
speeding up CPython.


More information about the Python-Dev mailing list