forked from zkcrypto/bellman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |