[Python-Dev] sum(...) limitation

Ethan Furman ethan at stoneleaf.us
Fri Aug 8 01:08:14 CEST 2014


On 08/07/2014 04:01 PM, Ethan Furman wrote:
> On 08/07/2014 03:06 PM, Chris Barker wrote:
>
> --> timeit.Timer("for string in ['booya'] * 100000: blah = blah + string", "blah = ''").repeat(3, 1)
> [0.021117210388183594, 0.013692855834960938, 0.00768280029296875]
>
> --> timeit.Timer("for string in ['booya'] * 100000: blah = string + blah", "blah = ''").repeat(3, 1)
> [15.301048994064331, 15.343288898468018, 15.268463850021362]

Oh, and the join() timings:

--> timeit.Timer("blah = ''.join(['booya'] * 100000)", "blah = ''").repeat(3, 1)
[0.0014629364013671875, 0.0014190673828125, 0.0011930465698242188]

So, + is three orders of magnitude slower than join.

--
~Ethan~


More information about the Python-Dev mailing list