From: aahz at netcom.com (Aahz Maruch) Date: Sat, 3 Apr 1999 00:01:31 GMT Subject: string.join() vs % and + operators References: <37054490.E79ADCC9@easystreet.com> Message-ID: Content-Length: 1175 X-UID: 396 In article <37054490.E79ADCC9 at easystreet.com>, Al Christians 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?