Skip to content

str.find equal length fast path #155555

Description

@dg-pb

Feature or enhancement

Proposal:

memcmp is being used in /Objects/stringlib/eq.h.
It can also be used as a fast path when 2 strings are of the same size for str.find and str.count.

PYMAIN="/Users/Edu/local/code/cpython/main/python.exe"
PYWT1="/Users/Edu/local/code/cpython/wt1/python.exe"
$PYMAIN -m timeit -s 'a = "abc" * 100_000; b = str(a)' 'a.find(b)'  # 273 µs
$PYWT1 -m timeit -s 'a = "abc" * 100_000; b = str(a)' 'a.find(b)'   #  11 µs

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedperformancePerformance or resource usagetype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions