Skip to content

Commit cfb0f11

Browse files
committed
add benchmark
1 parent fd0a331 commit cfb0f11

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/benches/slice.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::ptr::NonNull;
12
use test::black_box;
23
use test::Bencher;
34

@@ -162,3 +163,11 @@ fn fill_byte_sized(b: &mut Bencher) {
162163
black_box(slice.fill(black_box(NewType(42))));
163164
});
164165
}
166+
167+
// Tests the ability of the compiler to recognize that only the last slice item is needed
168+
// based on issue #106288
169+
#[bench]
170+
fn fold_to_last(b: &mut Bencher) {
171+
let slice: &[i32] = &[0; 1024];
172+
b.iter(|| black_box(slice).iter().fold(None, |_, r| Some(NonNull::from(r))));
173+
}

0 commit comments

Comments
 (0)