Stefan Krah <stefan-use...@bytereef.org> added the comment:

Kristján, could you check out the new implementation over at #10181?
I have trouble reproducing a big speed difference between bytearray
and memoryview (Linux, 64-bit). Here are the timings I get for the
current and the new version:


Slicing
-------

1) ./python -m timeit -n 10000000 -s "x = bytearray(b'x'*10000)" "x[:100]"
2) ./python -m timeit -n 10000000 -s "x = memoryview(bytearray(b'x'*10000))" 
"x[:100]"

1) cpython: 0.137 usec   pep-3118: 0.138 usec
2) cpython: 0.132 usec   pep-3118: 0.132 usec


Slicing with overhead for multidimensional capabilities:
--------------------------------------------------------

1) ./python  -m timeit -n 10000000 -s "import _testbuffer; x = 
_testbuffer.ndarray([ord('x') for _ in range(10000)], shape=[10000])" "x[:100]"
2) ./python  -m timeit -n 10000000 -s "import numpy; x = 
numpy.ndarray(buffer=bytearray(b'x'*10000), shape=[10000], dtype='B')" "x[:100]"

1) _testbuffer.c: 0.198 usec
2) numpy:         0.415 usec
Slice assignment
----------------

1) ./python -m timeit -n 10000000 -s "x = bytearray(b'x'*10000)" "x[5:10] = 
x[7:12]"
2) ./python -m timeit -n 10000000 -s "x = memoryview(bytearray(b'x'*10000))" 
"x[5:10] = x[7:12]"

1) cpython: 0.242 usec   pep-3118: 0.240 usec
2) cpython: 0.282 usec   pep-3118: 0.287 usec


Slice assignment, overhead for multidimensional capabilities
------------------------------------------------------------

1) ./python -m timeit -n 10000000 -s "import _testbuffer; x = 
_testbuffer.ndarray([ord('x') for _ in range(10000)], shape=[10000], 
flags=_testbuffer.ND_WRITABLE)" "x[5:10] = x[7:12]"

2) ./python -m timeit -n 10000000 -s "import numpy; x = 
numpy.ndarray(buffer=bytearray(b'x'*10000), shape=[10000], dtype='B')" "x[5:10] 
= x[7:12]"

_testbuffer.c: 0.469 usec
numpy:         1.37 usec


tolist
------

1) ./python -m timeit -n 10000 -s "import array; x = array.array('B', 
b'x'*10000)" "x.tolist()"
2) ./python -m timeit -n 10000 -s "x = memoryview(bytearray(b'x'*10000))" 
"x.tolist()"

1) cpython, array:      104.0 usec
2) pep-3118, memoryview: 90.5 usec


tolist, struct module overhead
------------------------------

1) ./python -m timeit -n 10000 -s "import _testbuffer; x = 
_testbuffer.ndarray([ord('x') for _ in range(10000)], shape=[10000])" 
"x.tolist()"
2) ./python -m timeit -n 10000 -s "import numpy; x = 
numpy.ndarray(buffer=bytearray(b'x'*10000), shape=[10000], dtype='B')" 
"x.tolist()"

_testbuffer.c: 1.38 msec (yes, that's microseconds!)
numpy:         104 usec

----------
nosy: +skrah

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10227>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to