Skip to content

Conversation

groutr
Copy link

@groutr groutr commented Aug 22, 2022

Simplified the implementation of interleave and made it slightly faster.

seqs = [range(1000) for i in range(100)]
%timeit list(interleave(seqs))

old: 5.07 ms ± 240 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
new: 4.03 ms ± 45.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

@groutr groutr changed the title Simplify up interleave. Simplify interleave. Aug 22, 2022
@eriknw
Copy link
Member

eriknw commented Oct 15, 2025

Thanks for working to clean this up and make it faster @groutr!

I noticed a difference with the new implementation:

>>> import toolz, cytoolz
>>> list(toolz.interleave([[1, 2], 'abcdef']))
[1, 'a', 2, 'b', 'c', 'd', 'e', 'f']
>>> list(cytoolz.interleave([[1, 2], 'abcdef']))
[1, 'a', 2, 'b', 'c']

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.

2 participants