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: 25% speed-up to common case for bisect()
Type: performance Stage: resolved
Components: Extension Modules Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: rhettinger, xtreak
Priority: normal Keywords: patch

Created on 2018-10-08 03:33 by rhettinger, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9753 merged rhettinger, 2018-10-08 03:35
Messages (2)
msg327317 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-10-08 03:33
The common case for bisect calls is to have two positional arguments and no keyword arguments.  For this case, PyArg_ParseTupleAndKeywords() is unnecessarily expensive.

Timings
-------

$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 152 nsec per loop
$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 152 nsec per loop
$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 152 nsec per loop

------- patched --------
$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 112 nsec per loop
$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 113 nsec per loop
$ pytime -r 11 -s 'from bisect import bisect' -s 'arr=list(range(5))' 'bisect(arr, 2)'
2000000 loops, best of 11: 113 nsec per loop
msg327355 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2018-10-08 15:02
New changeset de2e448414530689f2e60e84fd78bdfebb772898 by Raymond Hettinger in branch 'master':
bpo-34925: Optimize common case for bisect() argument parsing (#9753)
https://github.com/python/cpython/commit/de2e448414530689f2e60e84fd78bdfebb772898
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79106
2018-10-08 15:03:07rhettingersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-08 15:02:47rhettingersetmessages: + msg327355
2018-10-08 10:36:52xtreaksetnosy: + xtreak
2018-10-08 03:44:37rhettingersettitle: 25% speed-up to common case bisect() -> 25% speed-up to common case for bisect()
2018-10-08 03:35:54rhettingersetkeywords: + patch
stage: patch review
pull_requests: + pull_request9139
2018-10-08 03:33:04rhettingercreate