Skip to content

Commit

Permalink
Benchmark nth_back specializations too
Browse files Browse the repository at this point in the history
Similar to `nth` benchmark.

With this, all iterator method specializations are considered except for methods that rely on `[r]fold/try_[r]fold` by default.
We might want to add others later.
  • Loading branch information
Philippe-Cholet committed Oct 30, 2023
1 parent d1df7bf commit e8fd17b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions benches/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ macro_rules! bench_specializations {
black_box(x);
}
}));
$group.bench_function("nth_back", |bencher| bencher.iter(|| {
for start in 0_usize..10 {
for n in 0..10 {
let mut it = $iterator;
if let Some(s) = start.checked_sub(1) {
black_box(it.nth_back(s));
}
while let Some(x) = it.nth_back(n) {
black_box(x);
}
}
}
}));
$group.bench_function("rfold", |bencher| bencher.iter(|| {
$iterator.rfold((), |(), x| {
black_box(x);
Expand Down

0 comments on commit e8fd17b

Please sign in to comment.