This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rthr
Recipients martin.panter, r.david.murray, rthr
Date 2017-07-26.08:15:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1501056934.87.0.627514677577.issue31025@psf.upfronthosting.co.za>
In-reply-to
Content
BytesIO is heavily optimised to avoid copying bytes when it can.
For case (1), if you want to modify the data, then there is no need to actually copy it before overwriting it, because no-one else is using it

For case (2), if you want to change something, then you need to copy it first, otherwise the original bytes object would get modified


Case (1):
% python -m timeit -s "import io; b = io.BytesIO(b'0' * 2 ** 30)" "b.getbuffer()"
1000000 loops, best of 3: 0.201 usec per loop


Case (2):
python -m timeit -s "import io; a = b'0' * 2 ** 30; b = io.BytesIO(a)" "b.getbuffer()"
10 loops, best of 3: 54.5 msec per loop
History
Date User Action Args
2017-07-26 08:15:34rthrsetrecipients: + rthr, r.david.murray, martin.panter
2017-07-26 08:15:34rthrsetmessageid: <1501056934.87.0.627514677577.issue31025@psf.upfronthosting.co.za>
2017-07-26 08:15:34rthrlinkissue31025 messages
2017-07-26 08:15:34rthrcreate