Skip to content

Commit

Permalink
Switch benchmarks to iter_batched_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jan 11, 2024
1 parent 55a334b commit 7627b85
Showing 1 changed file with 33 additions and 26 deletions.
59 changes: 33 additions & 26 deletions benches/triptych.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extern crate alloc;

use alloc::sync::Arc;

use criterion::{black_box, Criterion};
use criterion::{black_box, BatchSize, Criterion};
use curve25519_dalek::{RistrettoPoint, Scalar};
use itertools::izip;
use merlin::Transcript;
Expand Down Expand Up @@ -91,12 +91,14 @@ fn generate_proof(c: &mut Criterion) {
let (witnesses, statements, transcripts) = generate_data(&params, 1, &mut rng);

// Start the benchmark
b.iter(|| {
// Generate the proof
black_box(
Proof::prove(&witnesses[0], &statements[0], &mut rng, &mut transcripts[0].clone()).unwrap(),
);
})
b.iter_batched_ref(
|| transcripts[0].clone(),
|t| {
// Generate the proof
Proof::prove(&witnesses[0], &statements[0], &mut rng, t).unwrap();
},
BatchSize::SmallInput,
)
});
}
}
Expand Down Expand Up @@ -125,13 +127,14 @@ fn generate_proof_vartime(c: &mut Criterion) {
let (witnesses, statements, transcripts) = generate_data(&params, 1, &mut rng);

// Start the benchmark
b.iter(|| {
// Generate the proof
black_box(
Proof::prove_vartime(&witnesses[0], &statements[0], &mut rng, &mut transcripts[0].clone())
.unwrap(),
);
})
b.iter_batched_ref(
|| transcripts[0].clone(),
|t| {
// Generate the proof
Proof::prove_vartime(&witnesses[0], &statements[0], &mut rng, t).unwrap();
},
BatchSize::SmallInput,
)
});
}
}
Expand All @@ -158,10 +161,14 @@ fn verify_proof(c: &mut Criterion) {
let proof = Proof::prove(&witnesses[0], &statements[0], &mut rng, &mut transcripts[0].clone()).unwrap();

// Start the benchmark
b.iter(|| {
// Verify the proof
assert!(black_box(proof.verify(&statements[0], &mut transcripts[0].clone())));
})
b.iter_batched_ref(
|| transcripts[0].clone(),
|t| {
// Verify the proof
assert!(black_box(proof.verify(&statements[0], t)));
},
BatchSize::SmallInput,
)
});
}
}
Expand Down Expand Up @@ -197,14 +204,14 @@ fn verify_batch_proof(c: &mut Criterion) {
.collect::<Vec<Proof>>();

// Start the benchmark
b.iter(|| {
// Verify the proofs in a batch
assert!(black_box(Proof::verify_batch(
&statements,
&proofs,
&mut transcripts.clone()
)));
})
b.iter_batched_ref(
|| transcripts.clone(),
|t| {
// Verify the proofs in a batch
assert!(Proof::verify_batch(&statements, &proofs, t));
},
BatchSize::SmallInput,
)
});
}
}
Expand Down

0 comments on commit 7627b85

Please sign in to comment.