diff --git a/Cargo.toml b/Cargo.toml index 37df7c5..7f2eea5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,13 @@ publish = false [package.metadata.docs.rs] rustdoc-args = [ "--html-in-header", "katex-header.html" ] +[dev-dependencies] +criterion = "0.3" + +[[bench]] +name = "plonk" +harness = false + [dependencies] subtle = "2.2.1" crossbeam-utils = "0.7" diff --git a/benches/plonk.rs b/benches/plonk.rs new file mode 100644 index 0000000..56228e0 --- /dev/null +++ b/benches/plonk.rs @@ -0,0 +1,42 @@ +#[macro_use] +extern crate criterion; + +extern crate halo2; +use crate::arithmetic::{small_multiexp, EqAffine, Field, Fp, Fq}; +use crate::poly::commitment::Params; +use crate::transcript::DummyHash; +use halo2::*; + +use criterion::{black_box, Criterion}; + +fn criterion_benchmark(c: &mut Criterion) { + // small multiexp + { + let params: Params = Params::new::>(5); + let g = &mut params.get_g(); + let len = g.len() / 2; + let (g_lo, g_hi) = g.split_at_mut(len); + + let coeff_1 = Fp::random(); + let coeff_2 = Fp::random(); + + c.bench_function("shared double-and-add", |b| { + b.iter(|| { + for (g_lo, g_hi) in g_lo.iter().zip(g_hi.iter()) { + small_multiexp(&[black_box(coeff_1), black_box(coeff_2)], &[*g_lo, *g_hi]); + } + }) + }); + + c.bench_function("double-and-add", |b| { + b.iter(|| { + for (g_lo, g_hi) in g_lo.iter().zip(g_hi.iter()) { + let _ = ((*g_lo) * coeff_1) + &((*g_hi) * coeff_2); + } + }) + }); + } +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); diff --git a/src/poly/commitment.rs b/src/poly/commitment.rs index eb24af9..b3fa7e0 100644 --- a/src/poly/commitment.rs +++ b/src/poly/commitment.rs @@ -261,6 +261,11 @@ impl Params { other_bases, } } + + /// Getter for g generators + pub fn get_g(&self) -> Vec { + self.g.clone() + } } /// A guard returned by the verifier