Skip to content

Commit

Permalink
Individual benches
Browse files Browse the repository at this point in the history
  • Loading branch information
claucece committed Aug 29, 2024
1 parent 87cb70f commit 454aa80
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boomerang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
pub mod client;
pub mod config;
pub mod server;
mod utils;
pub mod utils;
96 changes: 96 additions & 0 deletions macros/src/bench_tboomerang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,85 @@ macro_rules! bench_tboomerang_spending_m6_time {
};
}

#[macro_export]
macro_rules! bench_tboomerang_rewards_proof {
($config: ty, $bench_name: ident, $curve_name: tt) => {
pub fn $bench_name(c: &mut Criterion) {
let spend_state: Vec<<$config as CurveConfig>::ScalarField> =
vec![<$config as CurveConfig>::ScalarField::one()];
let policy_state: Vec<<$config as CurveConfig>::ScalarField> =
vec![<$config as CurveConfig>::ScalarField::from(2)];

c.bench_function(concat!($curve_name, " rewards-proof prove time"), |b| {
b.iter(|| {
RWP::<$config>::prove(
&spend_state,
&policy_state,
2,
<$config as CurveConfig>::ScalarField::from(2),
&mut OsRng,
);
});
});
}
};
}

#[macro_export]
macro_rules! bench_tboomerang_rewards_proof_verify {
($config: ty, $bench_name: ident, $curve_name: tt) => {
pub fn $bench_name(c: &mut Criterion) {
let spend_state: Vec<<$config as CurveConfig>::ScalarField> =
vec![<$config as CurveConfig>::ScalarField::one()];
let policy_state: Vec<<$config as CurveConfig>::ScalarField> =
vec![<$config as CurveConfig>::ScalarField::from(2)];
let proof = RWP::<$config>::prove(
&spend_state,
&policy_state,
2,
<$config as CurveConfig>::ScalarField::from(2),
&mut OsRng,
);

c.bench_function(concat!($curve_name, " rewards-proof verify time"), |b| {
b.iter(|| {
<Result<RWP<$config>, String> as Clone>::clone(&proof)
.expect("Failed to get rewards proof")
.verify(&spend_state);
});
});
}
};
}

#[macro_export]
macro_rules! bench_tboomerang_sub_proof {
($config: ty, $bench_name: ident, $curve_name: tt) => {
pub fn $bench_name(c: &mut Criterion) {
c.bench_function(concat!($curve_name, " sub-proof prove time"), |b| {
b.iter(|| {
SP::<$config>::prove(2, &mut OsRng);
});
});
}
};
}

#[macro_export]
macro_rules! bench_tboomerang_sub_proof_verify {
($config: ty, $bench_name: ident, $curve_name: tt) => {
pub fn $bench_name(c: &mut Criterion) {
let proof = SP::<$config>::prove(2, &mut OsRng);

c.bench_function(concat!($curve_name, " sub-proof verify time"), |b| {
b.iter(|| {
proof.verify();
});
});
}
};
}

#[macro_export]
macro_rules! bench_tboomerang_import_everything {
() => {
Expand All @@ -629,6 +708,7 @@ macro_rules! bench_tboomerang_import_everything {
client::SpendVerifyStateC as SVBC, client::UKeyPair as CBKP, config::BoomerangConfig,
server::CollectionStateS as CBSM, server::IssuanceStateS as IBSM,
server::ServerKeyPair as SBKP, server::SpendVerifyStateS as SVBS,
utils::rewards::BRewardsProof as RWP, utils::rewards::SubProof as SP,
};
use core::ops::Mul;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -665,6 +745,18 @@ macro_rules! bench_tboomerang_make_all {
$crate::bench_tboomerang_spending_m4_time!($config, boomerang_spending_m4, $curve_name);
$crate::bench_tboomerang_spending_m5_time!($config, boomerang_spending_m5, $curve_name);
$crate::bench_tboomerang_spending_m6_time!($config, boomerang_spending_m6, $curve_name);
$crate::bench_tboomerang_rewards_proof!($config, boomerang_rewards_proof, $curve_name);
$crate::bench_tboomerang_rewards_proof_verify!(
$config,
boomerang_rewards_proof_verify,
$curve_name
);
$crate::bench_tboomerang_sub_proof!($config, boomerang_sub_proof, $curve_name);
$crate::bench_tboomerang_sub_proof_verify!(
$config,
boomerang_sub_proof_verify,
$curve_name
);

criterion_group!(
benches,
Expand All @@ -685,6 +777,10 @@ macro_rules! bench_tboomerang_make_all {
boomerang_spending_m4,
boomerang_spending_m5,
boomerang_spending_m6,
boomerang_rewards_proof,
boomerang_rewards_proof_verify,
boomerang_sub_proof,
boomerang_sub_proof_verify,
);
criterion_main!(benches);
};
Expand Down

0 comments on commit 454aa80

Please sign in to comment.