From 4f4e75df61196275ed20a86e02499a4d7a1c04ae Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Wed, 6 Dec 2017 23:51:10 +0000 Subject: [PATCH] Add benches for multi_cartesian_product --- benches/bench1.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/benches/bench1.rs b/benches/bench1.rs index 077501ff2..d4342f93f 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -682,6 +682,38 @@ fn cartesian_product_fold(b: &mut test::Bencher) }) } +#[bench] +fn multi_cartesian_product_iterator(b: &mut test::Bencher) +{ + let xs = [vec![0; 16], vec![0; 16], vec![0; 16]]; + + b.iter(|| { + let mut sum = 0; + for x in xs.into_iter().multi_cartesian_product() { + sum += x[0]; + sum += x[1]; + sum += x[2]; + } + sum + }) +} + +#[bench] +fn multi_cartesian_product_fold(b: &mut test::Bencher) +{ + let xs = [vec![0; 16], vec![0; 16], vec![0; 16]]; + + b.iter(|| { + let mut sum = 0; + xs.into_iter().multi_cartesian_product().fold((), |(), x| { + sum += x[0]; + sum += x[1]; + sum += x[2]; + }); + sum + }) +} + #[bench] fn cartesian_product_nested_for(b: &mut test::Bencher) {