Add benchmarks for shared double-and-add

This commit is contained in:
therealyingtong 2020-09-16 00:44:56 +08:00
parent f2fc068db0
commit d70c8cc0d7
No known key found for this signature in database
GPG key ID: 179F32A1503D607E
3 changed files with 54 additions and 0 deletions

View file

@ -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"

42
benches/plonk.rs Normal file
View file

@ -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<EqAffine> = Params::new::<DummyHash<Fq>>(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);

View file

@ -261,6 +261,11 @@ impl<C: CurveAffine> Params<C> {
other_bases,
}
}
/// Getter for g generators
pub fn get_g(&self) -> Vec<C> {
self.g.clone()
}
}
/// A guard returned by the verifier