Skip to content

Commit 85cd49f

Browse files
committedJun 14, 2016
specialize zip: Add benchmarks
1 parent c2ef20f commit 85cd49f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
 

‎src/libcoretest/iter.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use core::{i8, i16, isize};
1313
use core::usize;
1414

1515
use test::Bencher;
16+
use test::black_box;
1617

1718
#[test]
1819
fn test_lt() {
@@ -1030,3 +1031,33 @@ fn bench_max(b: &mut Bencher) {
10301031
it.map(scatter).max()
10311032
})
10321033
}
1034+
1035+
pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
1036+
for (a, b) in ys.iter_mut().zip(xs) {
1037+
*a = *b;
1038+
}
1039+
}
1040+
1041+
pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
1042+
for (a, b) in ys.iter_mut().zip(xs) {
1043+
*a += *b;
1044+
}
1045+
}
1046+
1047+
#[bench]
1048+
fn bench_zip_copy(b: &mut Bencher) {
1049+
let source = vec![0u8; 16 * 1024];
1050+
let mut dst = black_box(vec![0u8; 16 * 1024]);
1051+
b.iter(|| {
1052+
copy_zip(&source, &mut dst)
1053+
})
1054+
}
1055+
1056+
#[bench]
1057+
fn bench_zip_add(b: &mut Bencher) {
1058+
let source = vec![1.; 16 * 1024];
1059+
let mut dst = vec![0.; 16 * 1024];
1060+
b.iter(|| {
1061+
add_zip(&source, &mut dst)
1062+
});
1063+
}

0 commit comments

Comments
 (0)
Please sign in to comment.