From 97fdd7726dfea605a7f9dc8ddb12e6aa37bc5e6f Mon Sep 17 00:00:00 2001 From: Joey Beauvais-Feisthauer Date: Tue, 28 Jun 2022 14:53:04 -0400 Subject: [PATCH] Make benchmarks work without odd-primes --- ext/crates/fp/benches/criterion.rs | 14 ++++++++++++-- ext/crates/fp/benches/iai.rs | 11 +++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ext/crates/fp/benches/criterion.rs b/ext/crates/fp/benches/criterion.rs index 15f97c906..00b8a8913 100644 --- a/ext/crates/fp/benches/criterion.rs +++ b/ext/crates/fp/benches/criterion.rs @@ -2,6 +2,11 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use fp::{matrix::Matrix, prime::ValidPrime}; use rand::Rng; +#[cfg(feature = "odd-primes")] +static TEST_PRIMES: [u32; 4] = [2, 3, 5, 7]; +#[cfg(not(feature = "odd-primes"))] +static TEST_PRIMES: [u32; 1] = [2]; + fn random_matrix(p: ValidPrime, dimension: usize) -> Matrix { Matrix::from_vec( p, @@ -12,10 +17,15 @@ fn random_matrix(p: ValidPrime, dimension: usize) -> Matrix { } fn row_reductions(c: &mut Criterion) { - for p in [2, 3, 5, 7].iter() { + for p in TEST_PRIMES.iter() { let p = ValidPrime::new(*p); let mut group = c.benchmark_group(&format!("row_reduce_{}", p)); - for dimension in [10, 20, 69, 100, 420, 1000, 1500] { + let sizes = if *p == 2 { + vec![10, 20, 69, 100, 420, 1000, 2000, 4000] + } else { + vec![10, 20, 69, 100, 420, 1000] + }; + for dimension in sizes { group.bench_function(&format!("row_reduce_{}_{}", p, dimension), move |b| { b.iter_batched_ref( || random_matrix(p, dimension), diff --git a/ext/crates/fp/benches/iai.rs b/ext/crates/fp/benches/iai.rs index 3ec9ba287..521eb30c8 100644 --- a/ext/crates/fp/benches/iai.rs +++ b/ext/crates/fp/benches/iai.rs @@ -117,6 +117,7 @@ fn row_reduce_7_420() { row_reduce_p_n(ValidPrime::new(7), 420); } +#[cfg(feature = "odd-primes")] iai::main!( row_reduce_2_10, row_reduce_2_20, @@ -143,3 +144,13 @@ iai::main!( row_reduce_7_420, row_reduce_7_1000, ); + +#[cfg(not(feature = "odd-primes"))] +iai::main!( + row_reduce_2_10, + row_reduce_2_20, + row_reduce_2_69, + row_reduce_2_100, + row_reduce_2_420, + row_reduce_2_1000, +);