Method much slower than function?

Grant Edwards grante at
Thu Jun 14 19:08:48 CEST 2007

On 2007-06-14, Steven D'Aprano <steve at> wrote:

> However, having said that, the speed difference does seem to be real: even
> when I correct the above issue, I get a large time difference using
> either or, and timeit agrees:
>>>> f = bar().readgenome
>>>> timeit.Timer("f(open('cb_foo'))", "from __main__ import f").timeit(5)
> 18.515995025634766
>>>> timeit.Timer("readgenome(open('cb_foo'))", "from __main__ import readgenome").timeit(5)
> 0.1940619945526123
> That's a difference of two orders of magnitude, and I can't see why.

Is it independent of the test order?

What happens when you reverse the order?

What happens if you run the same test twice in a row?

Grant Edwards                   grante             Yow! Thank god!! ... It's
                                  at               HENNY YOUNGMAN!!

More information about the Python-list mailing list