From 2bce1c31a6de18831d74d48bb90fc7f0acbf480e Mon Sep 17 00:00:00 2001 From: Remco Bloemen Date: Thu, 19 Nov 2020 12:07:28 -0800 Subject: [PATCH] Bench iter() and iter().rev() --- benches/core/matrix.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index 7b4f85bd..7f4432e3 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -136,6 +136,30 @@ fn mat500_mul_mat500(bench: &mut criterion::Criterion) { bench.bench_function("mat500_mul_mat500", move |bh| bh.iter(|| &a * &b)); } +fn iter(bench: &mut criterion::Criterion) { + let a = DMatrix::::new_random(1000, 1000); + + bench.bench_function("iter", move |bh| { + bh.iter(|| { + for value in a.iter() { + criterion::black_box(value); + } + }) + }); +} + +fn iter_rev(bench: &mut criterion::Criterion) { + let a = DMatrix::::new_random(1000, 1000); + + bench.bench_function("iter_rev", move |bh| { + bh.iter(|| { + for value in a.iter().rev() { + criterion::black_box(value); + } + }) + }); +} + fn copy_from(bench: &mut criterion::Criterion) { let a = DMatrix::::new_random(1000, 1000); let mut b = DMatrix::::new_random(1000, 1000); @@ -235,6 +259,8 @@ criterion_group!( mat10_mul_mat10_static, mat100_mul_mat100, mat500_mul_mat500, + iter, + iter_rev, copy_from, axpy, tr_mul_to,