Skip to content

Commit 2624523

Browse files
committed
add benchmark for generic slice PartialEq impl
1 parent 65519f5 commit 2624523

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/core/benches/slice.rs

+14
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,17 @@ fn fold_to_last(b: &mut Bencher) {
171171
let slice: &[i32] = &[0; 1024];
172172
b.iter(|| black_box(slice).iter().fold(None, |_, r| Some(NonNull::from(r))));
173173
}
174+
175+
#[bench]
176+
fn slice_cmp_generic(b: &mut Bencher) {
177+
#[derive(PartialEq, Clone, Copy)]
178+
struct Foo(u32, u32);
179+
180+
let left = [Foo(128, 128); 128];
181+
let right = [Foo(128, 128); 128];
182+
183+
b.iter(|| {
184+
let (left, right) = (black_box(&left), black_box(&right));
185+
left.as_slice() == right.as_slice()
186+
});
187+
}

0 commit comments

Comments
 (0)