Skip to content

Conversation

@hacatu
Copy link
Contributor

@hacatu hacatu commented Apr 15, 2025

Fixes #122

@pczarn pczarn self-assigned this May 31, 2025
@pczarn
Copy link
Contributor

pczarn commented May 31, 2025

We could have it documented that nth/skip is O(1) so nobody wonders about the reason this code is necessary (which is time complexity)

@pczarn
Copy link
Contributor

pczarn commented May 31, 2025

Could use a benchmark as well

@hacatu
Copy link
Contributor Author

hacatu commented May 31, 2025

Ok, I added a benchmark, basically create a bitvec where we skip the first 3 << 20 entries and read the last 16411 (much smaller) entries within the benchmark. This confirms what we expect:
before:

1,153,510.30 ns/iter (+/- 2,229.89)

after:

6,091.13 ns/iter (+/- 142.41)

I added an explanation that Iterator::skip will use Iterator::nth to the nth override, let me know if I should expand it

@pczarn pczarn merged commit 83f6838 into contain-rs:master Jun 2, 2025
5 checks passed
@pczarn
Copy link
Contributor

pczarn commented Jun 2, 2025

Thanks a lot!

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.

BitVec::Iter skip(n) is O(n) leading to bad performance

2 participants