mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Speed-up deque indexing by changing the deque block length to a power of two.
The division and modulo calculation in deque_item() can be compiled to fast bitwise operations when the BLOCKLEN is a power of two. Timing before: ~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]' 10000000 loops, best of 7: 0.0627 usec per loop Timing after: ~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]' 10000000 loops, best of 7: 0.0581 usec per loop
This commit is contained in:
parent
6597aa16b6
commit
de68e0cf0e
2 changed files with 2 additions and 2 deletions
|
@ -536,7 +536,7 @@ class TestBasic(unittest.TestCase):
|
|||
|
||||
@support.cpython_only
|
||||
def test_sizeof(self):
|
||||
BLOCKLEN = 62
|
||||
BLOCKLEN = 64
|
||||
basesize = support.calcobjsize('2P4nlP')
|
||||
blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
|
||||
self.assertEqual(object.__sizeof__(deque()), basesize)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue