[issue15381] Optimize BytesIO to so less reallocations when written, similarly to StringIO

Serhiy Storchaka report at bugs.python.org
Fri Jul 20 22:48:26 CEST 2012


Serhiy Storchaka <storchaka at gmail.com> added the comment:

> Under Windows (64-bit Windows 7 on a  VirtualBox VM), the patch increases performance slightly but not as much as under Linux:

Thank you, Antoine. This is an expected result.

> And the join() approach is 10x faster (!):
> C:\t\cpython>pc\VS9.0\amd64\python.exe -m timeit -s "import io; n=2000; d=[b'a'*
> n,b'bb'*n,b'ccc'*n]*1000"  "b''.join(d)"
> 100 loops, best of 3: 4.63 msec per loop

To be fair, test body should be: "s=[]; w=s.append"  "for x in d: w(x)"  "b''.join(s)"

May be tuning resize strategy (overallocate not 1/8, but 1/4, 1/2, or 100%) can help.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15381>
_______________________________________


More information about the Python-bugs-list mailing list