Skip to content

Conversation

@esarp
Copy link
Collaborator

@esarp esarp commented Dec 19, 2025

Rounding out #20387 and implementing bytes.endswith. Simple benchmark shows a ~6.4x improvement.

Tested with the following benchmark code:

import time


def bench(suffix: bytes, a: list[bytes], n: int) -> int:
    i = 0
    for x in range(n):
        for b in a:
            if b.endswith(suffix):
                i += 1
    return i


a = [b"foo", b"barasdfsf", b"foobar", b"ab", b"asrtert", b"sertyeryt"]
n = 5 * 1000 * 1000
suffix = b"foo"

bench(suffix, a, n)

t0 = time.time()
bench(suffix, a, n)
td = time.time() - t0
print(f"{td}s")

Output:

$ python bench.py         
0.9002199172973633s
$ python -c "import bench"
0.13828086853027344s

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.

1 participant