Skip to content

Instantly share code, notes, and snippets.

@ruuda
Created November 4, 2016 11:00
Show Gist options
  • Save ruuda/8af6b1f1a4a1c061e680de14cd7ec6fe to your computer and use it in GitHub Desktop.
Save ruuda/8af6b1f1a4a1c061e680de14cd7ec6fe to your computer and use it in GitHub Desktop.
#![feature(test)]
extern crate test;
macro_rules! unroll_10 {
{ $x: block } => {
$x $x $x $x $x $x $x $x $x $x
}
}
#[inline(always)]
fn do_bench_u8(b: &mut test::Bencher, from: usize, to: usize) {
let src = [2u8, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103];
b.iter(|| {
for _ in 0..10 {
let mut dst = [0_u8; 27];
let mut i = 0;
unroll_10! {{
let f = test::black_box(from);
let t = test::black_box(to);
(&mut dst[f+i..t+i]).copy_from_slice(&src[f+i..t+i]);
i = i + 1;
}};
test::black_box(dst);
}
});
}
#[inline(always)]
fn do_bench_u32(b: &mut test::Bencher, from: usize, to: usize) {
let src = [2u32, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103];
b.iter(|| {
for _ in 0..10 {
let mut dst = [0_u32; 27];
let mut i = 0;
unroll_10! {{
let f = test::black_box(from);
let t = test::black_box(to);
(&mut dst[f+i..t+i]).copy_from_slice(&src[f+i..t+i]);
i = i + 1;
}};
test::black_box(dst);
}
});
}
#[bench]
fn bench_copy_u8_slice_01_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 2);
}
#[bench]
fn bench_copy_u8_slice_02_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 3);
}
#[bench]
fn bench_copy_u8_slice_03_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 4);
}
#[bench]
fn bench_copy_u8_slice_04_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 5);
}
#[bench]
fn bench_copy_u8_slice_06_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 7);
}
#[bench]
fn bench_copy_u8_slice_08_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 9);
}
#[bench]
fn bench_copy_u8_slice_16_x100(b: &mut test::Bencher) {
do_bench_u8(b, 1, 17);
}
#[bench]
fn bench_copy_u32_slice_01_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 2);
}
#[bench]
fn bench_copy_u32_slice_02_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 3);
}
#[bench]
fn bench_copy_u32_slice_03_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 4);
}
#[bench]
fn bench_copy_u32_slice_04_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 5);
}
#[bench]
fn bench_copy_u32_slice_06_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 7);
}
#[bench]
fn bench_copy_u32_slice_08_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 9);
}
#[bench]
fn bench_copy_u32_slice_16_x100(b: &mut test::Bencher) {
do_bench_u32(b, 1, 17);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment