Skip to content

Performance loss for str.rstrip() for 3.13+ #131947

Open
@Alaeddine22

Description

@Alaeddine22

Description
Starting from Python3.12.0, I noticed that the rstrip function is slower than Python3.11.11
The following is a small table that compares the results of my test with different Python versions:

Image

Python3.11.10 VS Python3.11.11: I had almost the same value.
Python3.11.11 VS Python3.12.0: I had 25.91% loss.
Python3.11.11 VS Python3.12.9: I had 26.91% loss.
Python3.11.11 VS Python3.13.2: I had 15.94% loss.

Any explanation of this performance decrease ?
Thank you in advance.

Reproduction

  • pyenv install {version}
  • pyenv shell {version}
  • python3 -m timeit -n 1000 "for _ in range(10000): 'toto '.rstrip()"

Python versions tested on:
3.11.10
3.11.11
3.12.0
3.12.9
3.13.2

Operating systems tested on:
WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions