Skip to content

gh-162350: Use AC vectorcall for itertools.islice/ repeat - #162664

Open
tanloong wants to merge 6 commits into
python:mainfrom
tanloong:islice_repeat_vectorcall
Open

tanloong wants to merge 6 commits into
python:mainfrom
tanloong:islice_repeat_vectorcall

Conversation

@tanloong

@tanloong tanloong commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Replace hand-written constructors with AC + vectorcall.

Benchmark:

+----------------+--------+----------------------+
| Benchmark      | main   | patch                |
+================+========+======================+
| islice(x, 2)   | 191 ns | 148 ns: 1.29x faster |
+----------------+--------+----------------------+
| repeat(1)      | 182 ns | 115 ns: 1.59x faster |
+----------------+--------+----------------------+
| Geometric mean | (ref)  | 1.43x faster         |
+----------------+--------+----------------------+
Details
import pyperf

SETUP = """
import itertools
x = [1, 2, 3]
"""

CASES = [
    ('islice(x, 2)', 'itertools.islice(x, 2)'),
    ('repeat(1)', 'itertools.repeat(1)'),
]

runner = pyperf.Runner()
for name, stmt in CASES:
    runner.timeit(name, stmt=stmt, setup=SETUP)

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.

2 participants