Skip to content

Commit

Permalink
Ligero fix benches (#40)
Browse files Browse the repository at this point in the history
* fix bench call

* set num vars from 12-20
  • Loading branch information
mmagician committed Nov 15, 2023
1 parent 55fd8e5 commit db2e624
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
8 changes: 7 additions & 1 deletion bench-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ pub fn bench_pcs_method<
BenchmarkId::from_parameter(num_vars),
&num_vars,
|b, num_vars| {
b.iter(|| method(&ck, &vk, *num_vars, rand_poly));
b.iter_custom(|i| {
let mut time = Duration::from_nanos(0);
for _ in 0..i {
time += method(&ck, &vk, *num_vars, rand_poly);
}
time
});
},
);
}
Expand Down
5 changes: 5 additions & 0 deletions poly-commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ name = "size"
path = "benches/size.rs"
harness = false

[[bench]]
name = "ligero"
path = "benches/ligero.rs"
harness = false

[dev-dependencies]
ark-ed-on-bls12-381 = { version = "^0.4.0", default-features = false }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
Expand Down
40 changes: 11 additions & 29 deletions benches/benches.rs → poly-commit/benches/ligero.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![cfg(feature = "benches")]
use std::{borrow::Borrow, marker::PhantomData};

use ark_ff::PrimeField;
use ark_std::{rand::RngCore, test_rng};
use criterion::{criterion_group, criterion_main, Criterion};
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_std::{
rand::{Rng, RngCore},
test_rng,
};

use ark_crypto_primitives::{
crh::{CRHScheme, TwoToOneCRHScheme},
Expand All @@ -15,11 +17,10 @@ use ark_crypto_primitives::{
Error,
};

use ark_poly_commit::{
bench_templates::{bench_pcs_method, commit, open, verify, MLE},
linear_codes::{LinearCodePCS, MultilinearLigero},
};
use ark_pcs_bench_templates::*;
use ark_poly_commit::linear_codes::{LinearCodePCS, MultilinearLigero};

pub type MLE<F> = DenseMultilinearExtension<F>;
/// Generate default parameters for alpha = 17, state-size = 8
///
/// WARNING: This poseidon parameter is not secure. Please generate
Expand Down Expand Up @@ -164,27 +165,8 @@ type Ligero<F> = LinearCodePCS<
const MIN_NUM_VARS: usize = 12;
const MAX_NUM_VARS: usize = 22;

fn ligero_bn254(c: &mut Criterion) {
// only commit and open; verify is done in-circuit!
bench_pcs_method::<_, Ligero<Fr254>>(
c,
(MIN_NUM_VARS..MAX_NUM_VARS).step_by(2).collect(),
"commit_ligero_range_BN_254",
commit::<_, Ligero<Fr254>>,
);
bench_pcs_method::<_, Ligero<Fr254>>(
c,
(MIN_NUM_VARS..MAX_NUM_VARS).step_by(2).collect(),
"open_ligero_range_BN_254",
open::<_, Ligero<Fr254>>,
);
}

criterion_group! {
name = ligero_benches;
config = Criterion::default();
targets =
ligero_bn254,
fn rand_ml_poly<F: PrimeField>(num_vars: usize, rng: &mut impl Rng) -> MLE<F> {
MLE::rand(num_vars, rng)
}

criterion_main!(ligero_benches);
bench!(Ligero<Fr254>, rand_ml_poly);

0 comments on commit db2e624

Please sign in to comment.