StringType add operation seems every inefficient

David Fuess fuess at att.net
Wed Feb 14 08:48:31 EST 2001


Don't really know if it was expected, but the presence of the StringIO
module in both Python and "C" versions indicates that it was.

For really fast performance in string concatenation, use 
cStringIO, for a somewhat slower but more feature rich implementation
use StringIO.

Dave

On Wed, 14 Feb 2001 08:30:19 -0500, "Lee, Rick"
<rickylee at americasm01.nt.com> wrote:

>If I do something like this:
>
>s = ''
>for i in listOfStrings:
>    s = s + i
>
>Once listOfStrings is say 10000 members of 100 bytes, it takes forever
>(ie. minutes) for the "for" loop to finish.  This is running on a 700MHz
>WinNT machine, Python 2.0
>
>Contrast with:
>
>s = ''
>blocks = []
>for i in listOfStrings:
>    s = s + i
>    if len(s) > 4000
>        blocks.append(s); s = ''
>
>This takes a blink of the eye to finish, so it is faster than the first
>piece of code by between 100 and 1000 times.
>
>Is this relative inefficiency in the string add operation expected?
>
>I eventually have to produce a big long string of approx. 10MB.  What is
>the fastest way to do it without having to write C-extensions?
>
>- Rick Lee
>
>
>
>




More information about the Python-list mailing list