Migrate zcash_primitives benchmarks to criterion

This commit is contained in:
Jack Grigg 2019-12-19 16:11:11 -06:00
parent 7ea1da5d6f
commit 00499b3441
No known key found for this signature in database
GPG Key ID: 9E8255172BBF9898
3 changed files with 14 additions and 10 deletions

1
Cargo.lock generated
View File

@ -968,6 +968,7 @@ dependencies = [
"blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2s_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"crypto_api_chachapoly 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ff 0.5.0",
"fpe 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -31,11 +31,16 @@ sha2 = "0.8"
subtle = "2.2.1"
[dev-dependencies]
criterion = "0.3"
hex-literal = "0.2"
rand_xorshift = "0.2"
[features]
transparent-inputs = ["ripemd160", "secp256k1"]
[[bench]]
name = "pedersen_hash"
harness = false
[badges]
maintenance = { status = "actively-developed" }

View File

@ -1,17 +1,10 @@
#![feature(test)]
extern crate pairing;
extern crate rand_core;
extern crate test;
extern crate zcash_primitives;
use criterion::{criterion_group, criterion_main, Criterion};
use pairing::bls12_381::Bls12;
use rand_core::{OsRng, RngCore};
use zcash_primitives::jubjub::JubjubBls12;
use zcash_primitives::pedersen_hash::{pedersen_hash, Personalization};
#[bench]
fn bench_pedersen_hash(b: &mut test::Bencher) {
fn bench_pedersen_hash(c: &mut Criterion) {
let params = JubjubBls12::new();
let rng = &mut OsRng;
let bits = (0..510)
@ -19,5 +12,10 @@ fn bench_pedersen_hash(b: &mut test::Bencher) {
.collect::<Vec<_>>();
let personalization = Personalization::MerkleTree(31);
b.iter(|| pedersen_hash::<Bls12, _>(personalization, bits.clone(), &params));
c.bench_function("Pedersen hash", |b| {
b.iter(|| pedersen_hash::<Bls12, _>(personalization, bits.clone(), &params))
});
}
criterion_group!(benches, bench_pedersen_hash);
criterion_main!(benches);