Skip to content

Commit

Permalink
Parameterized benchmark group labels with flavor names in note_encryp…
Browse files Browse the repository at this point in the history
…tion and circuit benchmarks
  • Loading branch information
dmidem committed Jul 8, 2024
1 parent 80c7574 commit b72152a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
12 changes: 8 additions & 4 deletions benches/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ use orchard::{
circuit::{ProvingKey, VerifyingKey},
keys::{FullViewingKey, Scope, SpendingKey},
note::AssetBase,
orchard_flavor::{OrchardFlavor, OrchardVanilla, OrchardZSA},
orchard_flavor::{OrchardVanilla, OrchardZSA},
value::NoteValue,
Anchor, Bundle,
};
use rand::rngs::OsRng;

fn criterion_benchmark<FL: OrchardFlavor>(c: &mut Criterion) {
mod utils;

use utils::OrchardFlavorBench;

fn criterion_benchmark<FL: OrchardFlavorBench>(c: &mut Criterion) {
let rng = OsRng;

let sk = SpendingKey::from_bytes([7; 32]).unwrap();
Expand Down Expand Up @@ -56,7 +60,7 @@ fn criterion_benchmark<FL: OrchardFlavor>(c: &mut Criterion) {
let recipients_range = 1..=4;

{
let mut group = c.benchmark_group("proving");
let mut group = FL::benchmark_group(c, "proving");
group.sample_size(10);
for num_recipients in recipients_range.clone() {
let (bundle, instances) = create_bundle(num_recipients);
Expand All @@ -72,7 +76,7 @@ fn criterion_benchmark<FL: OrchardFlavor>(c: &mut Criterion) {
}

{
let mut group = c.benchmark_group("verifying");
let mut group = FL::benchmark_group(c, "verifying");
for num_recipients in recipients_range {
let (bundle, instances) = create_bundle(num_recipients);
let bundle = bundle
Expand Down
14 changes: 9 additions & 5 deletions benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use orchard::{
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendingKey},
note::AssetBase,
note_encryption::{CompactAction, OrchardDomain},
orchard_flavor::{OrchardFlavor, OrchardVanilla, OrchardZSA},
orchard_flavor::{OrchardVanilla, OrchardZSA},
value::NoteValue,
Anchor, Bundle,
};
Expand All @@ -15,7 +15,11 @@ use zcash_note_encryption_zsa::{batch, try_compact_note_decryption, try_note_dec
#[cfg(unix)]
use pprof::criterion::{Output, PProfProfiler};

fn bench_note_decryption<FL: OrchardFlavor>(c: &mut Criterion) {
mod utils;

use utils::OrchardFlavorBench;

fn bench_note_decryption<FL: OrchardFlavorBench>(c: &mut Criterion) {
let rng = OsRng;
let pk = ProvingKey::build::<FL>();

Expand Down Expand Up @@ -82,7 +86,7 @@ fn bench_note_decryption<FL: OrchardFlavor>(c: &mut Criterion) {
let domain = OrchardDomain::for_action(action);

let compact = {
let mut group = c.benchmark_group("note-decryption");
let mut group = FL::benchmark_group(c, "note-decryption");
group.throughput(Throughput::Elements(1));

group.bench_function("valid", |b| {
Expand All @@ -104,7 +108,7 @@ fn bench_note_decryption<FL: OrchardFlavor>(c: &mut Criterion) {
};

{
let mut group = c.benchmark_group("compact-note-decryption");
let mut group = FL::benchmark_group(c, "compact-note-decryption");
group.throughput(Throughput::Elements(invalid_ivks.len() as u64));
group.bench_function("invalid", |b| {
b.iter(|| {
Expand All @@ -131,7 +135,7 @@ fn bench_note_decryption<FL: OrchardFlavor>(c: &mut Criterion) {
})
.collect();

let mut group = c.benchmark_group("batch-note-decryption");
let mut group = FL::benchmark_group(c, "batch-note-decryption");

for size in [10, 50, 100] {
group.throughput(Throughput::Elements((ivks * size) as u64));
Expand Down
28 changes: 28 additions & 0 deletions benches/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use criterion::{measurement::Measurement, BenchmarkGroup, Criterion};

use orchard::orchard_flavor::{OrchardFlavor, OrchardVanilla, OrchardZSA};

pub(crate) trait OrchardFlavorBench: OrchardFlavor {
fn benchmark_group<'a, M: Measurement>(
c: &'a mut Criterion<M>,
group_name: &str,
) -> BenchmarkGroup<'a, M>;
}

impl OrchardFlavorBench for OrchardVanilla {
fn benchmark_group<'a, M: Measurement>(
c: &'a mut Criterion<M>,
group_name: &str,
) -> BenchmarkGroup<'a, M> {
c.benchmark_group(format!("[OrchardVanilla] {}", group_name))
}
}

impl OrchardFlavorBench for OrchardZSA {
fn benchmark_group<'a, M: Measurement>(
c: &'a mut Criterion<M>,
group_name: &str,
) -> BenchmarkGroup<'a, M> {
c.benchmark_group(format!("[OrchardZSA] {}", group_name))
}
}

0 comments on commit b72152a

Please sign in to comment.