Skip to content
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

Speed up zip_broadcast() by pre-filling the scalar elements #740

Merged
merged 2 commits into from
Jul 28, 2023

Conversation

kalekundert
Copy link
Contributor

#737 got me thinking about how to speed up zip_broadcast(), and one simple optimization I noticed is that there's no need to initialize the new_item list and fill in all the scalar values on every iteration. That only needs to be done once up front, since the loop will only ever alter the positions in new_item associated with the iterable arguments.

For the example given in #737, this new version is twice as fast as the old version:

New version:

>>> timeit('consume(zip_broadcast("_", "__", [1] * 100_000, [222] * 200_000))', globals=globals(), number=10)
0.45314044202677906

Old version:

>>> timeit('consume(zip_broadcast("_", "__", [1] * 100_000, [222] * 200_000))', globals=globals(), number=10)
1.0282995470333844

@bbayles bbayles merged commit 756e4c1 into more-itertools:master Jul 28, 2023
6 checks passed
lengau pushed a commit to canonical/charmcraft that referenced this pull request Sep 12, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [more-itertools](https://togithub.com/more-itertools/more-itertools) |
`==10.0.0` -> `==10.1.0` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/more-itertools/10.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/more-itertools/10.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/more-itertools/10.0.0/10.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/more-itertools/10.0.0/10.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>more-itertools/more-itertools (more-itertools)</summary>

###
[`v10.1.0`](https://togithub.com/more-itertools/more-itertools/releases/tag/v10.1.0):
Version 10.1.0

[Compare
Source](https://togithub.com/more-itertools/more-itertools/compare/v10.0.0...v10.1.0)

##### What's Changed

- Add more tests for `zip_broadcast()` by
[@&#8203;kalekundert](https://togithub.com/kalekundert) in
[more-itertools/more-itertools#739
- Added takewhile_inclusive by
[@&#8203;OlegAlexander](https://togithub.com/OlegAlexander) in
[more-itertools/more-itertools#736
- Speed up `zip_broadcast()` by pre-filling the scalar elements by
[@&#8203;kalekundert](https://togithub.com/kalekundert) in
[more-itertools/more-itertools#740
- Added outer_product. by
[@&#8203;OlegAlexander](https://togithub.com/OlegAlexander) in
[more-itertools/more-itertools#743
- Simplify `zip_broadcast` by
[@&#8203;pochmann](https://togithub.com/pochmann) in
[more-itertools/more-itertools#742
- Simplify `_zip_equal` by
[@&#8203;pochmann](https://togithub.com/pochmann) in
[more-itertools/more-itertools#744
- fix consume() type annotation by
[@&#8203;obaltian](https://togithub.com/obaltian) in
[more-itertools/more-itertools#746
- Version 10.1.0 by [@&#8203;bbayles](https://togithub.com/bbayles) in
[more-itertools/more-itertools#747

##### New Contributors

- [@&#8203;OlegAlexander](https://togithub.com/OlegAlexander) made their
first contribution in
[more-itertools/more-itertools#736
- [@&#8203;obaltian](https://togithub.com/obaltian) made their first
contribution in
[more-itertools/more-itertools#746

**Full Changelog**:
more-itertools/more-itertools@v10.0.1...v10.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "every weekend" in timezone Etc/UTC,
Automerge - "before 07:00" in timezone Etc/UTC.

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/canonical/charmcraft).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi44My4wIiwidXBkYXRlZEluVmVyIjoiMzYuODMuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

2 participants