Skip to content

Implement nth and nth_back to provide a O(1) way of skipping through elements #142

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

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

Conversation

cdellacqua
Copy link

By providing an override for the default implementation of nth (and nth_back), which in turn is used by skip, there is a noticeable improvement in performance, as jumping through elements becomes a constant time operation.

The implementation applies only to RingBufferIterator and RingBufferMutIterator, as they don't drop skipped elements.

Benchmarks

With 16 elements in the ringbuffer, criterion shows a 47% performance improvement

image

While with 1024 elements, criterion shows a 97% performance improvement

image

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