Skip to content

Commit

Permalink
Add benches for multi_cartesian_product
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz1000 committed Dec 6, 2017
1 parent 16c4606 commit 4f4e75d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 4f4e75d

Please sign in to comment.