string.join() vs % and + operators

Aahz Maruch aahz at netcom.com
Fri Apr 2 19:01:31 EST 1999


In article <37054490.E79ADCC9 at easystreet.com>,
Al Christians  <achrist at easystreet.com> wrote:
>
>This ran amazingly fast on my Pentium 200 Mhz -- around 11 seconds for
>Way 1, and 7 for Way 2.  So, either way, Python can put together about
>1 million little strings in a second.  Way 3, the way that one would 
>expect to be bad, recreating the string with each concatenation, was
>much slower, but only took about 1 minute.  Surprisingly swift as well.
>
>Anybody have anything to add to this?  Are there any related pitfalls
>that I may have missed?

Yup.  Using '+' for strings really bites when you've got long (or
potentially long) strings.  The average size of the string you're
concatenating is about a hundred characters; suppose you're doing CGI
work with redirects, and you're looking at closer to three hundred
characters a pop.

Try adding a 1K pre-string to the front of each of your Ways and see
what happens to the speed.
-- 
                      --- Aahz (@netcom.com)

Hugs and backrubs -- I break Rule 6       <*>      http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het

Why is this newsgroup different from all other newsgroups?




More information about the Python-list mailing list