Skip to content

Commit

Permalink
Add a simple multiexp benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed May 21, 2021
1 parent 7cde664 commit 9097dc6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ required-features = ["groth16"]
name = "batch"
harness = false

[[bench]]
name = "slow"
harness = false

[badges]
maintenance = { status = "actively-developed" }
48 changes: 48 additions & 0 deletions benches/slow.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use bellman::{
multicore::Worker,
multiexp::{multiexp, FullDensity},
};
use bls12_381::{Bls12, Scalar};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use ff::{Field, PrimeField};
use futures::Future;
use group::{Curve, Group};
use pairing::Engine;
use rand_core::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::sync::Arc;

fn bench_parts(c: &mut Criterion) {
let mut rng = XorShiftRng::from_seed([7; 16]);
let samples = 1 << 16;

let v = Arc::new(
(0..samples)
.map(|_| Scalar::random(&mut rng))
.collect::<Vec<_>>(),
);
let v_bits = Arc::new(v.iter().map(|e| e.to_le_bits()).collect::<Vec<_>>());
let g = Arc::new(
(0..samples)
.map(|_| <Bls12 as Engine>::G1::random(&mut rng).to_affine())
.collect::<Vec<_>>(),
);

let pool = Worker::new();

c.bench_with_input(
BenchmarkId::new("multiexp", samples),
&(pool, g, v_bits),
|b, (pool, g, v_bits)| {
b.iter(|| {
let _: <Bls12 as Engine>::G1 =
multiexp(pool, (g.clone(), 0), FullDensity, v_bits.clone())
.wait()
.unwrap();
})
},
);
}

criterion_group!(benches, bench_parts);
criterion_main!(benches);

0 comments on commit 9097dc6

Please sign in to comment.