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

Use "yield from" in merge_sorted #550

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

groutr
Copy link
Contributor

@groutr groutr commented Sep 14, 2022

Convert these loops:

for item in seq:
    yield item

To the more modern and slightly more efficient

yield from seq

A quick benchmark (a is a list of 30 sorted lists of 60 random integers)

# old
In [8]: %timeit list(merge_sorted(*a))
815 µs ± 31.3 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

# new
In [7]: %timeit list(merge_sorted(*a))
766 µs ± 26.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

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