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

Improve perfomance of PyLong_FromDouble() #82167

Closed
sir-sigurd mannequin opened this issue Aug 30, 2019 · 2 comments
Closed

Improve perfomance of PyLong_FromDouble() #82167

sir-sigurd mannequin opened this issue Aug 30, 2019 · 2 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage

Comments

@sir-sigurd
Copy link
Mannequin

sir-sigurd mannequin commented Aug 30, 2019

BPO 37986
Nosy @mdickinson, @sir-sigurd
PRs
  • bpo-37986: Improve perfomance of PyLong_FromDouble() #15611
  • Files
  • bench-long-from-float.py
  • 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 2020-05-10.09:21:34.511>
    created_at = <Date 2019-08-30.09:00:41.312>
    labels = ['interpreter-core', '3.9', 'performance']
    title = 'Improve perfomance of PyLong_FromDouble()'
    updated_at = <Date 2020-05-10.09:21:34.510>
    user = 'https://github.com/sir-sigurd'

    bugs.python.org fields:

    activity = <Date 2020-05-10.09:21:34.510>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-10.09:21:34.511>
    closer = 'mark.dickinson'
    components = ['Interpreter Core']
    creation = <Date 2019-08-30.09:00:41.312>
    creator = 'sir-sigurd'
    dependencies = []
    files = ['48573']
    hgrepos = []
    issue_num = 37986
    keywords = []
    message_count = 2.0
    messages = ['350861', '368574']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'sir-sigurd']
    pr_nums = ['15611']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue37986'
    versions = ['Python 3.9']

    @sir-sigurd
    Copy link
    Mannequin Author

    sir-sigurd mannequin commented Aug 30, 2019

    This patch simplifies fast path for floats that fit into C long and moves it from float.__trunc__ to PyLong_FromDouble().

    +---------------------+---------------------+------------------------------+
    | Benchmark | long-from-float-ref | long-from-float |
    +=====================+=====================+==============================+
    | int(1.) | 39.5 ns | 37.3 ns: 1.06x faster (-6%) |
    +---------------------+---------------------+------------------------------+
    | int(2.**20) | 46.4 ns | 45.6 ns: 1.02x faster (-2%) |
    +---------------------+---------------------+------------------------------+
    | int(2.**30) | 52.5 ns | 49.0 ns: 1.07x faster (-7%) |
    +---------------------+---------------------+------------------------------+
    | int(2.**60) | 50.0 ns | 49.2 ns: 1.02x faster (-2%) |
    +---------------------+---------------------+------------------------------+
    | int(-2.**63) | 76.6 ns | 48.6 ns: 1.58x faster (-37%) |
    +---------------------+---------------------+------------------------------+
    | int(2.**80) | 77.1 ns | 72.5 ns: 1.06x faster (-6%) |
    +---------------------+---------------------+------------------------------+
    | int(2.**120) | 91.5 ns | 87.7 ns: 1.04x faster (-4%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(1.) | 57.4 ns | 32.9 ns: 1.74x faster (-43%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(2.**20) | 60.5 ns | 41.3 ns: 1.47x faster (-32%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(2.**30) | 64.2 ns | 43.9 ns: 1.46x faster (-32%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(2.**60) | 66.3 ns | 42.3 ns: 1.57x faster (-36%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(-2.**63) | 67.7 ns | 43.1 ns: 1.57x faster (-36%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(2.**80) | 66.6 ns | 65.6 ns: 1.01x faster (-1%) |
    +---------------------+---------------------+------------------------------+
    | math.ceil(2.**120) | 79.9 ns | 80.5 ns: 1.01x slower (+1%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(1.) | 58.4 ns | 31.2 ns: 1.87x faster (-47%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(2.**20) | 61.0 ns | 39.6 ns: 1.54x faster (-35%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(2.**30) | 64.2 ns | 43.9 ns: 1.46x faster (-32%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(2.**60) | 62.1 ns | 40.1 ns: 1.55x faster (-35%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(-2.**63) | 64.1 ns | 39.9 ns: 1.61x faster (-38%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(2.**80) | 62.2 ns | 62.7 ns: 1.01x slower (+1%) |
    +---------------------+---------------------+------------------------------+
    | math.floor(2.**120) | 77.0 ns | 77.8 ns: 1.01x slower (+1%) |
    +---------------------+---------------------+------------------------------+

    I'm going to speed-up conversion of larger floats in a follow-up PR.

    @sir-sigurd sir-sigurd mannequin added 3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage labels Aug 30, 2019
    @mdickinson
    Copy link
    Member

    New changeset 86a93fd by Sergey Fedoseev in branch 'master':
    bpo-37986: Improve perfomance of PyLong_FromDouble() (GH-15611)
    86a93fd

    @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.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant