Message198385
If you delete a slice at the end of a bytearray, it is naturally optimized (thanks to the resizing strategy). However, if you delete a slice at the front of a bytearray, it is not: a memmove() gets done every time.
$ ./python -m timeit "b=bytearray(10000)" "while b: b[-1:] = b''"
100 loops, best of 3: 5.67 msec per loop
$ ./python -m timeit "b=bytearray(10000)" "while b: b[:1] = b''"
100 loops, best of 3: 6.67 msec per loop
$ ./python -m timeit "b=bytearray(50000)" "while b: b[-1:] = b''"
10 loops, best of 3: 28.3 msec per loop
$ ./python -m timeit "b=bytearray(50000)" "while b: b[:1] = b''"
10 loops, best of 3: 61.1 msec per loop
$ ./python -m timeit "b=bytearray(100000)" "while b: b[-1:] = b''"
10 loops, best of 3: 59.4 msec per loop
$ ./python -m timeit "b=bytearray(100000)" "while b: b[:1] = b''"
10 loops, best of 3: 198 msec per loop
This makes implementing a fifo using bytearray a bit suboptimal. It shouldn't be very hard to improve. |
|
Date |
User |
Action |
Args |
2013-09-25 14:03:50 | pitrou | set | recipients:
+ pitrou |
2013-09-25 14:03:50 | pitrou | set | messageid: <1380117830.08.0.43327617783.issue19087@psf.upfronthosting.co.za> |
2013-09-25 14:03:50 | pitrou | link | issue19087 messages |
2013-09-25 14:03:49 | pitrou | create | |
|