Skip to content

Commit

Permalink
add a benchmark for slice_iter.copied().array_chunks()
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Oct 17, 2022
1 parent 8be3ce9 commit 963d6f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions library/core/benches/iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use core::iter::*;
use core::mem;
use core::num::Wrapping;
use test::{black_box, Bencher};

#[bench]
Expand Down Expand Up @@ -398,3 +400,21 @@ fn bench_trusted_random_access_adapters(b: &mut Bencher) {
acc
})
}

/// Exercises the iter::Copied specialization for slice::Iter
#[bench]
fn bench_copied_array_chunks(b: &mut Bencher) {
let v = vec![1u8; 1024];

b.iter(|| {
black_box(&v)
.iter()
.copied()
.array_chunks::<{ mem::size_of::<u64>() }>()
.map(|ary| {
let d = u64::from_ne_bytes(ary);
Wrapping(d.rotate_left(7).wrapping_add(1))
})
.sum::<Wrapping<u64>>()
})
}
1 change: 1 addition & 0 deletions library/core/benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(int_log)]
#![feature(test)]
#![feature(trusted_random_access)]
#![feature(iter_array_chunks)]

extern crate test;

Expand Down

0 comments on commit 963d6f7

Please sign in to comment.