[Python-Dev] cpython: Issue #22003: When initialized from a bytes object, io.BytesIO() now

Antoine Pitrou antoine at python.org
Wed Jul 30 15:59:48 CEST 2014


Le 30/07/2014 02:11, Serhiy Storchaka a écrit :
> 30.07.14 06:59, Serhiy Storchaka написав(ла):
>> 30.07.14 02:45, antoine.pitrou написав(ла):
>>> http://hg.python.org/cpython/rev/79a5fbe2c78f
>>> changeset:   91935:79a5fbe2c78f
>>> parent:      91933:fbd104359ef8
>>> user:        Antoine Pitrou <solipsis at pitrou.net>
>>> date:        Tue Jul 29 19:41:11 2014 -0400
>>> summary:
>>>    Issue #22003: When initialized from a bytes object, io.BytesIO() now
>>> defers making a copy until it is mutated, improving performance and
>>> memory use on some use cases.
>>>
>>> Patch by David Wilson.
>>
>> Did you compare this with issue #15381 [1]?

Not really, but David's patch is simple enough and does a good job of 
accelerating the read-only BytesIO case.

> $ ./python -m timeit -s 'import i' 'i.readlines()'
>
> Before patch: 10 loops, best of 3: 46.9 msec per loop
> After issue22003 patch: 10 loops, best of 3: 36.4 msec per loop
> After issue15381 patch: 10 loops, best of 3: 27.6 msec per loop

I'm surprised your patch does better here. Any idea why?

Regards

Antoine.




More information about the Python-Dev mailing list