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

gh-124502: Add PyUnicode_Equal() function by vstinner · Pull Request #124504 · python/cpython · GitHub

/ cpython Public

gh-124502: Add PyUnicode_Equal() function - #124504

Merged
vstinner merged 6 commits into
python:mainfrom
vstinner:unicode_equal
Oct 7, 2024
Merged

gh-124502: Add PyUnicode_Equal() function#124504
vstinner merged 6 commits into
python:mainfrom
vstinner:unicode_equal

Conversation

vstinner commented Sep 25, 2024
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

Comment thread Doc/c-api/unicode.rst Outdated
Comment thread Doc/whatsnew/3.14.rst Outdated
Comment thread Objects/unicodeobject.c
Comment thread Doc/c-api/unicode.rst Outdated

Copy link
Copy Markdown
Member Author

@picnixz @rruuaanng @ZeroIntensity: I addressed your comments. Please review the updated PR.

picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Final nitpick but you can ignore it (I don't know whether it's that useful).

Comment thread Objects/unicodeobject.c Outdated

ZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you! LGTM.

Copy link
Copy Markdown
Contributor

Maybe you are right, But you can consider my suggestion.

Copy link
Copy Markdown
Member Author

I created capi-workgroup/decisions#43 issue in the C API Working Group.

vstinner commented Sep 26, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

I wrote a microbenchmark comparing equal strings of 10 characters:

Results on Fedora 40 with CPU isolation:

  • (private) _PyUnicode_EQ: Mean +- std dev: 9.71 ns +- 0.04 ns
  • (private) _PyUnicode_Equal: Mean +- std dev: 8.75 ns +- 0.01 ns
  • (public) PyUnicode_Equal: Mean +- std dev: 9.14 ns +- 0.02 ns
  • (public) PyUnicode_Compare: Mean +- std dev: 11.1 ns +- 0.1 ns
  • (public) PyUnicode_RichCompare: Mean +- std dev: 12.2 ns +- 0.0 ns

Proposed public PyUnicode_Equal() is 1.2x faster than PyUnicode_Compare() (-2.0 ns) and 1.3x faster than PyUnicode_RichCompare() (-3.1 ns).

Private _PyUnicode_EQ() and private _PyUnicode_Equal() are not exactly the same implementation, it seems like private _PyUnicode_Equal() is a little bit faster (1 ns!).

vstinner commented Sep 30, 2024
edited
Loading

Copy link
Copy Markdown
Member Author

Microbenchmark on comparison of inequal strings of 10 characters, only the last character is different.

  • (private) _PyUnicode_EQ: Mean +- std dev: 10.0 ns +- 0.0 ns
  • (private) _PyUnicode_Equal: Mean +- std dev: 9.18 ns +- 0.00 ns
  • (public) PyUnicode_Equal: Mean +- std dev: 10.1 ns +- 0.0 ns
  • (public) PyUnicode_Compare: Mean +- std dev: 10.9 ns +- 0.0 ns
  • (public) PyUnicode_RichCompare: Mean +- std dev: 13.1 ns +- 0.0 ns

vstinner enabled auto-merge (squash) October 7, 2024 21:07

vstinner commented Oct 7, 2024

Copy link
Copy Markdown
Member Author

I created capi-workgroup/decisions#43 issue in the C API Working Group.

The C API Working Group approved the API.

vstinner merged commit a7f0727 into python:main Oct 7, 2024
vstinner deleted the unicode_equal branch October 7, 2024 21:24

vstinner commented Oct 7, 2024

Copy link
Copy Markdown
Member Author

Merged. Thanks for reviews @picnixz and @ZeroIntensity.

efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull request Oct 9, 2024
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL