summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_deque.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-07-06 04:05:29 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-07-06 04:05:29 (GMT)
commitde68e0cf0e6d94b087a3b7ae40e50843dff6d918 (patch)
tree9413154444e873a334d1885e0a78ef9181708fab /Lib/test/test_deque.py
parent6597aa16b6044d8b5e31e176fed1865471499f08 (diff)
downloadcpython-de68e0cf0e6d94b087a3b7ae40e50843dff6d918.zip
cpython-de68e0cf0e6d94b087a3b7ae40e50843dff6d918.tar.gz
cpython-de68e0cf0e6d94b087a3b7ae40e50843dff6d918.tar.bz2
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
Diffstat (limited to 'Lib/test/test_deque.py')
-rw-r--r--Lib/test/test_deque.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py
index a8487d2..e782b99 100644
--- a/Lib/test/test_deque.py
+++ b/Lib/test/test_deque.py
@@ -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)