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

Convert str(), bytes() and bytearray() to Argument Clinic #85506

Closed
serhiy-storchaka opened this issue Jul 18, 2020 · 2 comments
Closed

Convert str(), bytes() and bytearray() to Argument Clinic #85506

serhiy-storchaka opened this issue Jul 18, 2020 · 2 comments

Comments

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 18, 2020

BPO 41334
Nosy @vstinner, @larryhastings, @ezio-melotti, @serhiy-storchaka, @tirkarthi
PRs
  • #21535
  • 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-07-20.12:56:38.790>
    created_at = <Date 2020-07-18.14:58:51.115>
    labels = ['3.10', 'expert-installation', 'expert-argument-clinic', 'expert-unicode', 'performance']
    title = 'Convert str(), bytes() and bytearray() to Argument Clinic'
    updated_at = <Date 2020-07-20.12:56:38.790>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2020-07-20.12:56:38.790>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-07-20.12:56:38.790>
    closer = 'serhiy.storchaka'
    components = ['Installation', 'Unicode', 'Argument Clinic']
    creation = <Date 2020-07-18.14:58:51.115>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41334
    keywords = ['patch']
    message_count = 2.0
    messages = ['373906', '374003']
    nosy_count = 5.0
    nosy_names = ['vstinner', 'larry', 'ezio.melotti', 'serhiy.storchaka', 'xtreak']
    pr_nums = ['21535']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue41334'
    versions = ['Python 3.10']

    @serhiy-storchaka
    Copy link
    Member Author

    @serhiy-storchaka serhiy-storchaka commented Jul 18, 2020

    Constructors str(), bytes() and bytearray() were not converted to Argument Clinic because it was not possible to generate correct signature for them. But now there is other reason of using Argument Clinic -- it generates more efficient code for parsing arguments.

    The proposed PR converts str(), bytes() and bytearray() to Argument Clinic but generated docstrings are not used.

    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str()"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 81.9 ns +- 4.5 ns -> [/home/serhiy/py/cpython-release/python] 60.0 ns +- 1.9 ns: 1.36x faster (-27%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str('abcdefgh')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 121 ns +- 3 ns -> [/home/serhiy/py/cpython-release/python] 87.6 ns +- 2.8 ns: 1.38x faster (-28%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(12345)"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 188 ns +- 8 ns -> [/home/serhiy/py/cpython-release/python] 149 ns +- 5 ns: 1.27x faster (-21%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', 'ascii')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 210 ns +- 7 ns -> [/home/serhiy/py/cpython-release/python] 164 ns +- 6 ns: 1.28x faster (-22%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', 'ascii', 'strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 222 ns +- 9 ns -> [/home/serhiy/py/cpython-release/python] 170 ns +- 6 ns: 1.30x faster (-23%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "str(b'abcdefgh', encoding='ascii', errors='strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 488 ns +- 20 ns -> [/home/serhiy/py/cpython-release/python] 306 ns +- 5 ns: 1.59x faster (-37%)
    
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes()"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 85.1 ns +- 2.2 ns -> [/home/serhiy/py/cpython-release/python] 60.2 ns +- 2.3 ns: 1.41x faster (-29%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes(8)"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 160 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 115 ns +- 4 ns: 1.39x faster (-28%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes(b'abcdefgh')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 131 ns +- 6 ns -> [/home/serhiy/py/cpython-release/python] 91.0 ns +- 2.8 ns: 1.43x faster (-30%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', 'ascii')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 190 ns +- 6 ns -> [/home/serhiy/py/cpython-release/python] 144 ns +- 5 ns: 1.32x faster (-24%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', 'ascii', 'strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 214 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 156 ns +- 4 ns: 1.37x faster (-27%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytes('abcdefgh', encoding='ascii', errors='strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 442 ns +- 9 ns -> [/home/serhiy/py/cpython-release/python] 269 ns +- 8 ns: 1.64x faster (-39%)
    
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray()"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 93.5 ns +- 2.1 ns -> [/home/serhiy/py/cpython-release/python] 73.1 ns +- 1.8 ns: 1.28x faster (-22%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray(8)"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 154 ns +- 3 ns -> [/home/serhiy/py/cpython-release/python] 117 ns +- 3 ns: 1.32x faster (-24%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray(b'abcdefgh')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 164 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 131 ns +- 2 ns: 1.25x faster (-20%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', 'ascii')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 239 ns +- 7 ns -> [/home/serhiy/py/cpython-release/python] 193 ns +- 4 ns: 1.24x faster (-19%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', 'ascii', 'strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 260 ns +- 5 ns -> [/home/serhiy/py/cpython-release/python] 207 ns +- 10 ns: 1.26x faster (-21%)
    $ ./python -m pyperf timeit -q --compare-to=../cpython-release2/python "bytearray('abcdefgh', encoding='ascii', errors='strict')"
    Mean +- std dev: [/home/serhiy/py/cpython-release2/python] 505 ns +- 11 ns -> [/home/serhiy/py/cpython-release/python] 322 ns +- 7 ns: 1.57x faster (-36%)

    @serhiy-storchaka
    Copy link
    Member Author

    @serhiy-storchaka serhiy-storchaka commented Jul 20, 2020

    New changeset 12f4334 by Serhiy Storchaka in branch 'master':
    bpo-41334: Convert constructors of str, bytes and bytearray to Argument Clinic (GH-21535)
    12f4334

    @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
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant