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
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com