You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.4 KiB

From: aahz at (Aahz Maruch)
Date: Sat, 3 Apr 1999 00:01:31 GMT
Subject: string.join() vs % and + operators
References: <>
Message-ID: <>
Content-Length: 1175
X-UID: 396
In article <37054490.E79ADCC9 at>,
Al Christians <achrist at> 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 (
Hugs and backrubs -- I break Rule 6 <*>
Androgynous poly kinky vanilla queer het
Why is this newsgroup different from all other newsgroups?