ringbuffer
ringbuffer copied to clipboard
Implement nth and nth_back to provide a O(1) way of skipping through elements
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
While with 1024 elements, criterion shows a 97% performance improvement