Python 3 read() function

MRAB google at mrabarnett.plus.com
Thu Dec 4 20:40:49 CET 2008


Terry Reedy wrote:
> Дамјан Георгиевски wrote:
>>> I don't think it matters.  Here's a quick comparison between 2.5 and
>>> 3.0 on a relatively small 17 meg file:
>>>
>>> C:\>c:\Python30\python -m timeit -n 1
>>> "open('C:\\work\\temp\\bppd_vsub.csv', 'rb').read()"
>>> 1 loops, best of 3: 36.8 sec per loop
>>>
>>> C:\>c:\Python25\python -m timeit -n 1
>>> "open('C:\\work\\temp\\bppd_vsub.csv', 'rb').read()"
>>> 1 loops, best of 3: 33 msec per loop
>>>
>>> That's 3 orders of magnitude slower on python3.0!
>>
>> Isn't this because you have the file cached in memory on the second run? 
> 
> In my test, I read Python25.chm with 2.5 and Python30.chm with 3.0.
> 
> Rereading Python30.chm without closing *is* much faster.
>  >>> f=open('Doc/Python30.chm','rb')
>  >>> d=f.read()
>  >>> d=f.read()
>  >>> d=f.read()
> Closing, reopening, and rereading is slower.
> 
It certainly is faster if you're already at the end of the file. :-)



More information about the Python-list mailing list