add benchmark

This commit is contained in:
The 8472 2023-01-02 05:17:47 +01:00
parent fd0a3313f7
commit cfb0f11a9f

View File

@ -1,3 +1,4 @@
use core::ptr::NonNull;
use test::black_box;
use test::Bencher;
@ -162,3 +163,11 @@ fn fill_byte_sized(b: &mut Bencher) {
black_box(slice.fill(black_box(NewType(42))));
});
}
// Tests the ability of the compiler to recognize that only the last slice item is needed
// based on issue #106288
#[bench]
fn fold_to_last(b: &mut Bencher) {
let slice: &[i32] = &[0; 1024];
b.iter(|| black_box(slice).iter().fold(None, |_, r| Some(NonNull::from(r))));
}