PATCH: Speed up direct string concatenation by 20+%!
Steve Holden
steve at holdenweb.com
Sat Sep 30 03:01:31 EDT 2006
Larry Hastings wrote:
> Fredrik Lundh wrote:
>
>>so what does the benchmark look like if you actually do this ?
>
>
> Okay, timing this:
> x = ""
> for i in range(100000):
> x += "a"
> t = x[1] # forces the concat object to render
>
> The result:
> Python 2.5 release: 30.0s
> Python 2.5 locally built: 30.2s
> Python 2.5 concat: 4.3s
> Improvement: 600% (1/7 of the time)
>
>
> /larry/
>
Interesting. Does a comparison also force it to render? If not, I wonder
if comparisons might not end up slower. It does sound like memory usage
might go through the roof with this technique under certain
circumstances, so the more extensive your tests are the more likely you
are to see the change actually used (I'm not convinced you'll persuade
the developers to include this).
Whether or not it does get incorporated I think it's a great
demonstration of how amenable Python is to experimentation with
alternate representations, and I think your project might make a very
interesting PyCon paper for people who were thinking about joining the
development effort but hadn't yet started.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list