]> git.lizzy.rs Git - rust.git/commitdiff
specialize zip: Add benchmarks
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Thu, 21 Apr 2016 19:35:39 +0000 (21:35 +0200)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Tue, 14 Jun 2016 13:51:49 +0000 (15:51 +0200)
src/libcoretest/iter.rs

index 54fca291e5ec2c464e8a8896c257d422c3eea12a..a2848faa105e9a89cf2d53ac158cc181720eb43c 100644 (file)
@@ -13,6 +13,7 @@
 use core::usize;
 
 use test::Bencher;
+use test::black_box;
 
 #[test]
 fn test_lt() {
@@ -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)
+    });
+}