faster way for adding many strings

Peter Hansen peter at engcorp.com
Tue Sep 17 08:32:06 EDT 2002


Ulli Stein wrote:
> Hi,
> 
> What is the faster way: appending many strings to a list and then joining 
> them, or writing to 
> StringIO and then getvalue()?

Alex' detailed response notwithstanding, there's another usual
answer to your question:

"Premature optimization is the root of all evil in programming"
(D. Knuth)

It means you usually shouldn't care which is faster until (a) your
software is working fully, and (b) you have profiled the code
and determined that in fact you have an unacceptable bottleneck
which must be optimized to meet your requirements.

Don't get me wrong, there _are_ times to optimize.  You just
shouldn't see them very often... and life is simpler that way. :)

-Peter




More information about the Python-list mailing list