Skip to content

Speed up itertools.pairwise #118218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hauntsaninja opened this issue Apr 24, 2024 · 1 comment
Closed

Speed up itertools.pairwise #118218

hauntsaninja opened this issue Apr 24, 2024 · 1 comment
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage type-feature A feature request or enhancement

Comments

@hauntsaninja
Copy link
Contributor

hauntsaninja commented Apr 24, 2024

The pairwise implementation mentions that we can reuse the result tuple

There's currently some discussion of performance ongoing at https://discuss.python.org/t/nwise-itertools/51718

Linked PRs

@hauntsaninja hauntsaninja added the type-feature A feature request or enhancement label Apr 24, 2024
@AlexWaygood AlexWaygood added performance Performance or resource usage extension-modules C modules in the Modules dir labels Apr 24, 2024
hauntsaninja added a commit to hauntsaninja/cpython that referenced this issue Apr 24, 2024
With this change:
```
b1(1)            min=152.8us mean=155.5us ± 3.8us (25 repeats, 1000 loops)
b2(1)            min=149.0us mean=159.1us ± 8.8us (25 repeats, 1000 loops)
b3(1)            min=232.6us mean=242.5us ± 11.7us (25 repeats, 1000 loops)
b1(10)           min=279.2us mean=296.9us ± 16.6us (25 repeats, 1000 loops)
b2(10)           min=249.5us mean=259.2us ± 12.2us (25 repeats, 1000 loops)
b3(10)           min=386.6us mean=398.8us ± 10.1us (25 repeats, 1000 loops)
b1(1000)         min=20.3ms mean=20.7ms ± 0.5ms (25 repeats, 1000 loops)
b2(1000)         min=16.7ms mean=17.1ms ± 0.2ms (25 repeats, 1000 loops)
b3(1000)         min=26.0ms mean=26.2ms ± 0.3ms (25 repeats, 1000 loops)
```
Without this change:
```
b1(1)            min=142.2us mean=143.0us ± 0.9us (25 repeats, 1000 loops)
b2(1)            min=142.7us mean=143.3us ± 1.0us (25 repeats, 1000 loops)
b3(1)            min=219.8us mean=227.2us ± 4.4us (25 repeats, 1000 loops)
b1(10)           min=314.2us mean=323.8us ± 4.1us (25 repeats, 1000 loops)
b2(10)           min=335.4us mean=341.8us ± 5.1us (25 repeats, 1000 loops)
b3(10)           min=362.0us mean=386.2us ± 14.9us (25 repeats, 1000 loops)
b1(1000)         min=26.5ms mean=27.3ms ± 0.3ms (25 repeats, 1000 loops)
b2(1000)         min=29.8ms mean=30.2ms ± 0.2ms (25 repeats, 1000 loops)
b3(1000)         min=26.0ms mean=26.5ms ± 0.4ms (25 repeats, 1000 loops)
```
@eendebakpt
Copy link
Contributor

eendebakpt commented Apr 24, 2024

Also see #118222 (improve performance of pairwise by replacing PyTuple_Pack)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants