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

Faster getrandbits() for small integers #60878

Closed
serhiy-storchaka opened this issue Dec 13, 2012 · 3 comments
Closed

Faster getrandbits() for small integers #60878

serhiy-storchaka opened this issue Dec 13, 2012 · 3 comments
Assignees
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@serhiy-storchaka
Copy link
Member

BPO 16674
Nosy @rhettinger, @jcea, @mdickinson, @serhiy-storchaka
Files
  • random_getrandbits_fastpath.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2013-01-04.10:21:59.593>
    created_at = <Date 2012-12-13.20:54:36.065>
    labels = ['extension-modules', 'performance']
    title = 'Faster getrandbits() for small integers'
    updated_at = <Date 2013-01-04.10:21:59.592>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2013-01-04.10:21:59.592>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2013-01-04.10:21:59.593>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2012-12-13.20:54:36.065>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['28304']
    hgrepos = []
    issue_num = 16674
    keywords = ['patch']
    message_count = 3.0
    messages = ['177436', '178990', '179012']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'jcea', 'mark.dickinson', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue16674'
    versions = ['Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    The proposed patch adds a fast patch for generating small integers (the most common use case).

    Microbenchmark:
    $ ./python -m timeit -s "import random; r=random.getrandbits; n=30" "r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n);r(n)"

    Non patched: 4.27 usec per loop
    Patched: 2.97 usec per loop

    @serhiy-storchaka serhiy-storchaka added extension-modules C modules in the Modules dir performance Performance or resource usage labels Dec 13, 2012
    @serhiy-storchaka serhiy-storchaka self-assigned this Dec 29, 2012
    @mdickinson
    Copy link
    Member

    Looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 4, 2013

    New changeset b0926ddcab5e by Serhiy Storchaka in branch 'default':
    Issue bpo-16674: random.getrandbits() is now 20-40% faster for small integers.
    http://hg.python.org/cpython/rev/b0926ddcab5e

    @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
    extension-modules C modules in the Modules dir performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants