Skip to content

Commit

Permalink
Make benchmarks work without odd-primes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Jun 28, 2022
1 parent 6b8ae36 commit d23e594
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ext/crates/fp/benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
11 changes: 11 additions & 0 deletions ext/crates/fp/benches/iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
);

0 comments on commit d23e594

Please sign in to comment.