From e8fd17b86d426ab3aa12b667f23ad7eb0da81a28 Mon Sep 17 00:00:00 2001 From: Philippe-Cholet Date: Mon, 30 Oct 2023 11:59:38 +0100 Subject: [PATCH] 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. --- benches/specializations.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/benches/specializations.rs b/benches/specializations.rs index b98b7e5eb..139270897 100644 --- a/benches/specializations.rs +++ b/benches/specializations.rs @@ -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);