FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr() by vstinner · Pull Request #125214 · python/cpython · GitHub

Repository navigation

gh-125196: Add fast-path for int in PyUnicodeWriter_WriteStr() - #125214

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:writer_specialize
Oct 9, 2024
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:writer_specialize

Conversation

vstinner commented Oct 9, 2024 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call directly _PyLong_FormatWriter() if the object is an int.

PyUnicodeWriter_WriteStr() and PyUnicodeWriter_WriteRepr() now call
directly _PyLong_FormatWriter() if the object is an int.

vstinner commented Oct 9, 2024

Copy link
Copy Markdown
Member Author

Benchmark using PR gh-125202 as reference:

import pyperf
runner = pyperf.Runner()

runner.bench_func('repr([1,2,3])', repr, [1, 2, 3])
list2 = [123]*10
runner.bench_func('repr(list2)', repr, list2)
list3 = [123]*50
runner.bench_func('repr(list3)', repr, list3)

Comparison without / with this change:

+----------------+---------+-----------------------+
| Benchmark      | ref     | change                |
+================+=========+=======================+
| repr([1,2,3])  | 291 ns  | 189 ns: 1.54x faster  |
+----------------+---------+-----------------------+
| repr(list2)    | 822 ns  | 498 ns: 1.65x faster  |
+----------------+---------+-----------------------+
| repr(list3)    | 3.01 us | 1.56 us: 1.93x faster |
+----------------+---------+-----------------------+
| Geometric mean | (ref)   | 1.70x faster          |
+----------------+---------+-----------------------+

vstinner merged commit ee3167b into python:main Oct 9, 2024
vstinner deleted the writer_specialize branch October 9, 2024 22:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL