Method much slower than function?

Francesco Guerrieri f.guerrieri at gmail.com
Thu Jun 14 10:54:25 CEST 2007


On 6/14/07, Peter Otten <__peter__ at web.de> 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?

Francesco



More information about the Python-list mailing list