[New-bugs-announce] [issue34302] Avoid inefficient way to find start point in deque.index

ksg97031 report at bugs.python.org
Tue Jul 31 22:31:05 EDT 2018


New submission from ksg97031 <ksg97031 at gmail.com>:

Source base : heads/master:b75d7e2435, Aug  1 2018, 10:32:28

$ cat 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

----------------------

----------
components: Library (Lib)
messages: 322834
nosy: ksg97031, rhettinger
priority: normal
severity: normal
status: open
title: Avoid inefficient way to find start point in deque.index
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34302>
_______________________________________


More information about the New-bugs-announce mailing list