From db2e62408c4d4f157eefaa42ca177d7caefada2c Mon Sep 17 00:00:00 2001 From: mmagician Date: Mon, 13 Nov 2023 10:40:39 +0100 Subject: [PATCH] Ligero fix benches (#40) * fix bench call * set num vars from 12-20 --- bench-templates/src/lib.rs | 8 +++- poly-commit/Cargo.toml | 5 +++ .../benches/ligero.rs | 40 +++++-------------- 3 files changed, 23 insertions(+), 30 deletions(-) rename benches/benches.rs => poly-commit/benches/ligero.rs (83%) diff --git a/bench-templates/src/lib.rs b/bench-templates/src/lib.rs index 1594ee7c..bb200f7e 100644 --- a/bench-templates/src/lib.rs +++ b/bench-templates/src/lib.rs @@ -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 + }); }, ); } diff --git a/poly-commit/Cargo.toml b/poly-commit/Cargo.toml index 258ad659..70aa94bc 100644 --- a/poly-commit/Cargo.toml +++ b/poly-commit/Cargo.toml @@ -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" ] } diff --git a/benches/benches.rs b/poly-commit/benches/ligero.rs similarity index 83% rename from benches/benches.rs rename to poly-commit/benches/ligero.rs index f421f270..69a7dc1e 100644 --- a/benches/benches.rs +++ b/poly-commit/benches/ligero.rs @@ -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}, @@ -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 = DenseMultilinearExtension; /// Generate default parameters for alpha = 17, state-size = 8 /// /// WARNING: This poseidon parameter is not secure. Please generate @@ -164,27 +165,8 @@ type Ligero = 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>( - c, - (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2).collect(), - "commit_ligero_range_BN_254", - commit::<_, Ligero>, - ); - bench_pcs_method::<_, Ligero>( - c, - (MIN_NUM_VARS..MAX_NUM_VARS).step_by(2).collect(), - "open_ligero_range_BN_254", - open::<_, Ligero>, - ); -} - -criterion_group! { - name = ligero_benches; - config = Criterion::default(); - targets = - ligero_bn254, +fn rand_ml_poly(num_vars: usize, rng: &mut impl Rng) -> MLE { + MLE::rand(num_vars, rng) } -criterion_main!(ligero_benches); +bench!(Ligero, rand_ml_poly);