Fix Pedersen hash benchmark
This commit is contained in:
parent
b955ff7c7e
commit
34cd43a8f2
|
@ -78,3 +78,7 @@ test-dependencies = [
|
|||
"incrementalmerkletree/test-dependencies",
|
||||
"proptest",
|
||||
]
|
||||
|
||||
[[bench]]
|
||||
name = "pedersen_hash"
|
||||
harness = false
|
||||
|
|
|
@ -1,23 +1,28 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate rand;
|
||||
extern crate test;
|
||||
extern crate pairing;
|
||||
extern crate sapling_crypto;
|
||||
|
||||
use rand::{Rand, thread_rng};
|
||||
use pairing::bls12_381::Bls12;
|
||||
use sapling_crypto::jubjub::JubjubBls12;
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use rand_core::{OsRng, RngCore};
|
||||
use sapling_crypto::pedersen_hash::{pedersen_hash, Personalization};
|
||||
|
||||
#[bench]
|
||||
fn bench_pedersen_hash(b: &mut test::Bencher) {
|
||||
let params = JubjubBls12::new();
|
||||
let rng = &mut thread_rng();
|
||||
let bits = (0..510).map(|_| bool::rand(rng)).collect::<Vec<_>>();
|
||||
#[cfg(unix)]
|
||||
use pprof::criterion::{Output, PProfProfiler};
|
||||
|
||||
fn bench_pedersen_hash(c: &mut Criterion) {
|
||||
let rng = &mut OsRng;
|
||||
let bits = (0..510)
|
||||
.map(|_| (rng.next_u32() % 2) != 0)
|
||||
.collect::<Vec<_>>();
|
||||
let personalization = Personalization::MerkleTree(31);
|
||||
|
||||
b.iter(|| {
|
||||
pedersen_hash::<Bls12, _>(personalization, bits.clone(), ¶ms)
|
||||
c.bench_function("pedersen-hash", |b| {
|
||||
b.iter(|| pedersen_hash(personalization, bits.clone()))
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
|
||||
targets = bench_pedersen_hash
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
criterion_group!(benches, bench_pedersen_hash);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in New Issue