[Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Wed Jun 8 07:05:19 EDT 2016
- Previous message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Next message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 08.06.16 13:37, Paul Sokolovsky wrote:
The obvious way to create the bytes object of length n is b'\0' * n. That's very inefficient: it requires allocating useless b'\0', then a generic function to repeat arbitrary memory block N times. If there's a talk of Python to not be laughed at for being SLOW, there would rather be efficient ways to deal with blocks of binary data.
Do you have any evidences for this claim?
$ ./python -m timeit -s 'n = 10000' -- 'bytes(n)' 1000000 loops, best of 3: 1.32 usec per loop $ ./python -m timeit -s 'n = 10000' -- 'b"\0" * n' 1000000 loops, best of 3: 0.858 usec per loop
- Previous message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Next message (by thread): [Python-Dev] PEP 467: Minor API improvements to bytes, bytearray, and memoryview
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]