En Thu, 14 Jun 2007 05:54:25 -0300, Francesco Guerrieri <[EMAIL PROTECTED]> escribió:
> On 6/14/07, Peter Otten <[EMAIL PROTECTED]> wrote: >> Gabriel Genellina wrote: >> > ... >> > py> print timeit.Timer("f2()", "from __main__ import >> f2").repeat(number=1) >> > [0.42673663831576358, 0.42807591467630662, 0.44401481193838876] >> > py> print timeit.Timer("f1()", "from __main__ import >> f1").repeat(number=1) >> > >> > ...after a few minutes I aborted the process... >> >> I can't confirm this. > > [...] > >> $ python2.5 -m timeit -s 'from join import f1' 'f1()' >> 10 loops, best of 3: 212 msec per loop >> $ python2.5 -m timeit -s 'from join import f2' 'f2()' >> 10 loops, best of 3: 259 msec per loop >> $ python2.5 -m timeit -s 'from join import f3' 'f3()' >> 10 loops, best of 3: 236 msec per loop > > On my machine (using python 2.5 under win xp) the results are: >>>> print timeit.Timer("f2()", "from __main__ import f2").repeat(number = >>>> 1) > [0.19726834822823575, 0.19324697456408974, 0.19474492594212861] >>>> print timeit.Timer("f1()", "from __main__ import f1").repeat(number = >>>> 1) > [21.982707133304167, 21.905312587963252, 22.843430035622767] > > so it seems that there is a rather sensible difference. > what's the reason of the apparent inconsistency with Peter's test? I left the test running and went to sleep. Now, the results: C:\TEMP>python -m timeit -s "from join import f1" "f1()" 10 loops, best of 3: 47.7 sec per loop C:\TEMP>python -m timeit -s "from join import f2" "f2()" 10 loops, best of 3: 317 msec per loop C:\TEMP>python -m timeit -s "from join import f3" "f3()" 10 loops, best of 3: 297 msec per loop Yes, 47.7 *seconds* to build the string using the += operator. I don't know what's the difference: python version (this is not 2.5.1 final), hardware, OS... but certainly in this PC it is *very* important. Memory usage was around 40MB (for a 10MB string) and CPU usage went to 99% (!). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list