Skip to content

Commit 9d84fe1

Browse files
Benchmark nth_back specializations too
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.
1 parent 55c97ce commit 9d84fe1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

benches/specializations.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ macro_rules! bench_specializations {
100100
black_box(x);
101101
}
102102
}));
103+
$group.bench_function("nth_back", |bencher| bencher.iter(|| {
104+
for start in 0_usize..10 {
105+
for n in 0..10 {
106+
let mut it = $iterator;
107+
if let Some(s) = start.checked_sub(1) {
108+
black_box(it.nth_back(s));
109+
}
110+
while let Some(x) = it.nth_back(n) {
111+
black_box(x);
112+
}
113+
}
114+
}
115+
}));
103116
$group.bench_function("rfold", |bencher| bencher.iter(|| {
104117
$iterator.rfold((), |(), x| {
105118
black_box(x);

0 commit comments

Comments
 (0)