Author skrah
Recipients kristjan.jonsson, mark.dickinson, pitrou, scoder, skrah
Date 2011-09-08.14:55:20
SpamBayes Score 0.000318862
Marked as misclassified No
Message-id <1315493721.53.0.358356334193.issue10227@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-09-08 14:55:21skrahsetrecipients: + skrah, mark.dickinson, pitrou, scoder, kristjan.jonsson
2011-09-08 14:55:21skrahsetmessageid: <1315493721.53.0.358356334193.issue10227@psf.upfronthosting.co.za>
2011-09-08 14:55:20skrahlinkissue10227 messages
2011-09-08 14:55:20skrahcreate