[Python-ideas] Create a StringBuilder class and use it everywhere
dirkjan at ochtman.nl
Mon Aug 29 10:35:27 CEST 2011
On Thu, Aug 25, 2011 at 11:45, M.-A. Lemburg <mal at egenix.com> wrote:
> I think you should use cStringIO in your class implementation.
> The list + join idiom is nice, but it has the disadvantage of
> creating and keeping alive many small string objects (with all
> the memory overhead and fragmentation that goes along with it).
AFAIK using cStringIO just for string building is much slower than
using list.append() + join(). IIRC we tested some micro-benchmarks on
this for Mercurial output (where it was a significant part of the
profile for some commands). That was on Python 2, of course, it may be
better in io.StringIO and/or Python 3.
More information about the Python-ideas