This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Avoid inefficient way to find start point in deque.index
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: hacksg, rhettinger
Priority: normal Keywords: patch

Created on 2018-07-31 17:49 by hacksg, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8589 closed hacksg, 2018-07-31 17:50
Messages (3)
msg322804 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-07-31 18:04
Please run some timings to show whether the improvement is significant.  Also, please sign a CLA.
msg322832 - (view) Author: Seonggi Kim (hacksg) * Date: 2018-08-01 01:43
Base commit : Python 3.8.0a0 (heads/master:b75d7e2435, Aug  1 2018, 10:32:28)

$ test.py
import timeit

queue_setup = '''
from collections import deque
q = deque()
start = 10**5
stop = start + 500
for i in range(0, stop):
    q.append(i)
'''

code = '''
index = q.index(30, 1, stop)
assert index == 30
'''
code2 = '''
index = q.index((start >> 1) + 1, start >> 1, stop >> 1)
assert index == (start >> 1) + 1
'''
code3 = '''
index = q.index(start + 1, start, stop)
assert index == start + 1
'''

repeat = 100000
print(timeit.timeit(setup = queue_setup, stmt = code, number = repeat * 20))
print(timeit.timeit(setup = queue_setup, stmt = code2, number = repeat))
print(timeit.timeit(setup = queue_setup, stmt = code3, number = repeat))
$ ./python_cur.exe test.py
2.154346022
2.899595406
5.265440983

$ ./python_ksg.exe test.py
2.1457827320000002
0.717190736
1.9934196979999999
msg322835 - (view) Author: Seonggi Kim (hacksg) * Date: 2018-08-01 02:31
Request PR again : https://bugs.python.org/issue34302
History
Date User Action Args
2022-04-11 14:59:04adminsetgithub: 78479
2018-08-01 02:31:25hacksgsetstatus: open -> closed

messages: + msg322835
stage: patch review -> resolved
2018-08-01 01:43:43hacksgsetmessages: + msg322832
2018-07-31 18:04:20rhettingersetversions: - Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7
nosy: + rhettinger

messages: + msg322804

components: + Library (Lib), - Extension Modules
2018-07-31 17:50:10hacksgsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8098
2018-07-31 17:49:14hacksgcreate