Skip to content

Commit

Permalink
specialize zip: Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jun 14, 2016
1 parent c2ef20f commit 85cd49f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/libcoretest/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use core::{i8, i16, isize};
use core::usize;

use test::Bencher;
use test::black_box;

#[test]
fn test_lt() {
Expand Down Expand Up @@ -1030,3 +1031,33 @@ fn bench_max(b: &mut Bencher) {
it.map(scatter).max()
})
}

pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
for (a, b) in ys.iter_mut().zip(xs) {
*a = *b;
}
}

pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
for (a, b) in ys.iter_mut().zip(xs) {
*a += *b;
}
}

#[bench]
fn bench_zip_copy(b: &mut Bencher) {
let source = vec![0u8; 16 * 1024];
let mut dst = black_box(vec![0u8; 16 * 1024]);
b.iter(|| {
copy_zip(&source, &mut dst)
})
}

#[bench]
fn bench_zip_add(b: &mut Bencher) {
let source = vec![1.; 16 * 1024];
let mut dst = vec![0.; 16 * 1024];
b.iter(|| {
add_zip(&source, &mut dst)
});
}

0 comments on commit 85cd49f

Please sign in to comment.