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

Refactor duplicate code calculating digit's bit length #72807

Closed
adrian17 mannequin opened this issue Nov 5, 2016 · 5 comments
Closed

Refactor duplicate code calculating digit's bit length #72807

adrian17 mannequin opened this issue Nov 5, 2016 · 5 comments
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@adrian17
Copy link
Mannequin

adrian17 mannequin commented Nov 5, 2016

BPO 28621
Nosy @mdickinson, @serhiy-storchaka, @adrian17
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • bit_length.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 = None
    closed_at = <Date 2016-11-08.18:36:05.507>
    created_at = <Date 2016-11-05.19:37:28.766>
    labels = ['interpreter-core', '3.7', 'performance']
    title = "Refactor duplicate code calculating digit's bit length"
    updated_at = <Date 2017-03-31.16:36:09.041>
    user = 'https://github.com/adrian17'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:09.041>
    actor = 'dstufft'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-11-08.18:36:05.507>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-11-05.19:37:28.766>
    creator = 'Adrian Wielgosik'
    dependencies = []
    files = ['45367']
    hgrepos = []
    issue_num = 28621
    keywords = ['patch']
    message_count = 5.0
    messages = ['280123', '280131', '280240', '280331', '280333']
    nosy_count = 4.0
    nosy_names = ['mark.dickinson', 'python-dev', 'serhiy.storchaka', 'Adrian Wielgosik']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue28621'
    versions = ['Python 3.7']

    @adrian17
    Copy link
    Mannequin Author

    adrian17 mannequin commented Nov 5, 2016

    The attached patch uses an existing function bits_in_digit() in two other functions:

    • in long_bit_length() - it already had identical logic
    • in _PyLong_NumBits() - it used a naive, slower way of calculating bit length, so as an added bonus the patch speeds it up a bit. It's visible in float-long comparison microbenchmark:
    $ ./old -m timeit "1 == 1.0"
    5000000 loops, best of 5: 55 nsec per loop
    
    $ ./new -m timeit "1 == 1.0"
    5000000 loops, best of 5: 52.3 nsec per loop
    
    $ ./old -m timeit "12345678 == 12345678.0"
    5000000 loops, best of 5: 70.4 nsec per loop
    
    $ ./new -m timeit "12345678 == 12345678.0"
    5000000 loops, best of 5: 53.5 nsec per loop

    @adrian17 adrian17 mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Nov 5, 2016
    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    @mdickinson
    Copy link
    Member

    LGTM, too.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 8, 2016

    New changeset 1940b72b0a02 by Serhiy Storchaka in branch 'default':
    Issue bpo-28621: Sped up converting int to float by reusing faster bits counting
    https://hg.python.org/cpython/rev/1940b72b0a02

    @serhiy-storchaka
    Copy link
    Member

    Thank you Adrian for your contribution.

    @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.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants