Python example: possible speedup?

Aahz Maruch aahz at netcom.com
Thu Sep 9 17:26:12 EDT 1999


In article <Pine.LNX.4.10.9909090140160.24091-100000 at starship.python.net>,
Moshe Zadka  <moshez at server.python.net> wrote:
>
>Note an important speed-up in concatenating strings: use cStringIO:
>
>a=cStringIO.StringIO()
>for i in range(10000):
>	a.write('h')
>a=a.getvalue()
>
>rather then:
>
>a=''
>for  i in range(10000):
>	a=a+'h'

I'll test this if I have to, but do you know off-hand how this compares
to

a = []
for i in range(10000):
    a.append('h')
a = string.join(a,'')

What if you use range(100000) or range(1000000)?
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list