zcash_proof: Migrate benchmark to criterion
Closes zcash/librustzcash#282.
This commit is contained in:
parent
50140c521a
commit
9acf763b8f
|
@ -30,6 +30,7 @@ wagyu-zcash-parameters = { version = "0.2", optional = true }
|
|||
zcash_primitives = { version = "0.3", path = "../zcash_primitives" }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
rand_xorshift = "0.2"
|
||||
|
||||
[features]
|
||||
|
@ -39,6 +40,11 @@ download-params = ["minreq"]
|
|||
local-prover = ["directories"]
|
||||
multicore = ["bellman/multicore"]
|
||||
|
||||
[[bench]]
|
||||
name = "sapling"
|
||||
harness = false
|
||||
required-features = ["local-prover"]
|
||||
|
||||
[[example]]
|
||||
name = "get-params-path"
|
||||
required-features = ["directories"]
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
#[macro_use]
|
||||
extern crate criterion;
|
||||
|
||||
use bellman::groth16::*;
|
||||
use bls12_381::Bls12;
|
||||
use criterion::Criterion;
|
||||
use ff::Field;
|
||||
use group::Group;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::time::{Duration, Instant};
|
||||
use zcash_primitives::primitives::{Diversifier, ProofGenerationKey, ValueCommitment};
|
||||
use zcash_proofs::circuit::sapling::Spend;
|
||||
|
||||
const TREE_DEPTH: usize = 32;
|
||||
|
||||
fn main() {
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let rng = &mut XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x3d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
||||
0xe5,
|
||||
]);
|
||||
|
||||
println!("Creating sample parameters...");
|
||||
let groth_params = generate_random_parameters::<Bls12, _, _>(
|
||||
Spend {
|
||||
value_commitment: None,
|
||||
|
@ -31,10 +33,7 @@ fn main() {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
const SAMPLES: u32 = 50;
|
||||
|
||||
let mut total_time = Duration::new(0, 0);
|
||||
for _ in 0..SAMPLES {
|
||||
c.bench_function("sapling", |b| {
|
||||
let value_commitment = ValueCommitment {
|
||||
value: 1,
|
||||
randomness: jubjub::Fr::random(rng),
|
||||
|
@ -71,25 +70,26 @@ fn main() {
|
|||
let ar = jubjub::Fr::random(rng);
|
||||
let anchor = bls12_381::Scalar::random(rng);
|
||||
|
||||
let start = Instant::now();
|
||||
let _ = create_random_proof(
|
||||
Spend {
|
||||
value_commitment: Some(value_commitment),
|
||||
proof_generation_key: Some(proof_generation_key),
|
||||
payment_address: Some(payment_address),
|
||||
commitment_randomness: Some(commitment_randomness),
|
||||
ar: Some(ar),
|
||||
auth_path: auth_path,
|
||||
anchor: Some(anchor),
|
||||
},
|
||||
&groth_params,
|
||||
rng,
|
||||
)
|
||||
.unwrap();
|
||||
total_time += start.elapsed();
|
||||
}
|
||||
let avg = total_time / SAMPLES;
|
||||
let avg = avg.subsec_nanos() as f64 / 1_000_000_000f64 + (avg.as_secs() as f64);
|
||||
|
||||
println!("Average proving time (in seconds): {}", avg);
|
||||
b.iter(|| {
|
||||
create_random_proof(
|
||||
Spend {
|
||||
value_commitment: Some(value_commitment.clone()),
|
||||
proof_generation_key: Some(proof_generation_key.clone()),
|
||||
payment_address: Some(payment_address.clone()),
|
||||
commitment_randomness: Some(commitment_randomness),
|
||||
ar: Some(ar),
|
||||
auth_path: auth_path.clone(),
|
||||
anchor: Some(anchor),
|
||||
},
|
||||
&groth_params,
|
||||
rng,
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
name = benches;
|
||||
config = Criterion::default().sample_size(10);
|
||||
targets = criterion_benchmark);
|
||||
criterion_main!(benches);
|
Loading…
Reference in New Issue