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 defaultdict for collecting intermediate values in merge_with #532

Merged
merged 1 commit into from May 26, 2022

Conversation

groutr
Copy link
Contributor

@groutr groutr commented May 2, 2022

This approach also avoids calling factory() twice. It combines the ideas of itertoolz.groupby and cytoolz.merge_with.

Best of all: there is a small performance gain:

In [2]: rand_d = [dict(zip(range(50), range(50))) for i in range(100)]

In [12]: %timeit merge_with(max, rand_d)
527 µs ± 14.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [13]: %timeit toolz.merge_with(max, rand_d)
730 µs ± 24.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

This approach also avoids calling factory twice.
@groutr
Copy link
Contributor Author

groutr commented May 6, 2022

ping @eriknw

@eriknw
Copy link
Member

eriknw commented May 26, 2022

LGTM, thanks @groutr!

@eriknw eriknw merged commit 03a7efd into pytoolz:master May 26, 2022
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