ringbuffer icon indicating copy to clipboard operation
ringbuffer copied to clipboard

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

Open cdellacqua opened this issue 10 months ago • 0 comments

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

cdellacqua avatar Jan 31 '25 21:01 cdellacqua