Method much slower than function?

Diez B. Roggisch deets at nospam.web.de
Thu Jun 14 12:03:24 EDT 2007


Grant Edwards schrieb:
> On 2007-06-14, Leo Kislov <Leo.Kislov at gmail.com> wrote:
>> On Jun 13, 5:40 pm, ido... at gmail.com wrote:
>>> Hi all,
>>>
>>> I am running Python 2.5 on Feisty Ubuntu. I came across some code that
>>> is substantially slower when in a method than in a function.
>>>
>>>>>> cProfile.run("bar.readgenome(open('cb_foo'))")
>>>          20004 function calls in 10.214 CPU seconds
>>>>>> cProfile.run("z=r.readgenome(open('cb_foo'))")
>>>          20004 function calls in 0.041 CPU seconds
>>>
>> I suspect open files are cached
> 
> They shouldn't be.
> 
>> so the second reader picks up where the first one left: at the
>> of the file.
> 
> That sounds like a bug.  Opening a file a second time should
> produce a "new" file object with the file-pointer at the
> beginning of the file.

It's a OS thing.

Diez



More information about the Python-list mailing list