Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25% speed-up to common case for bisect() #79106

Closed
rhettinger opened this issue Oct 8, 2018 · 2 comments
Closed

25% speed-up to common case for bisect() #79106

rhettinger opened this issue Oct 8, 2018 · 2 comments
Labels
3.8 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@rhettinger
Copy link
Contributor

BPO 34925
Nosy @rhettinger, @tirkarthi
PRs
  • bpo-34925: Optimize common case for bisect() argument parsing #9753
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-10-08.15:03:07.462>
    created_at = <Date 2018-10-08.03:33:04.720>
    labels = ['extension-modules', '3.8', 'performance']
    title = '25% speed-up to common case for bisect()'
    updated_at = <Date 2018-10-08.15:03:07.461>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2018-10-08.15:03:07.461>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-08.15:03:07.462>
    closer = 'rhettinger'
    components = ['Extension Modules']
    creation = <Date 2018-10-08.03:33:04.720>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34925
    keywords = ['patch']
    message_count = 2.0
    messages = ['327317', '327355']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'xtreak']
    pr_nums = ['9753']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue34925'
    versions = ['Python 3.8']

    @rhettinger
    Copy link
    Contributor Author

    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

    @rhettinger rhettinger added 3.8 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage labels Oct 8, 2018
    @rhettinger rhettinger changed the title 25% speed-up to common case bisect() 25% speed-up to common case for bisect() Oct 8, 2018
    @rhettinger
    Copy link
    Contributor Author

    New changeset de2e448 by Raymond Hettinger in branch 'master':
    bpo-34925: Optimize common case for bisect() argument parsing (bpo-9753)
    de2e448

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes extension-modules C modules in the Modules dir performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant