Skip to content

Commit

Permalink
Benches: Using longer variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
rrtoledo committed Dec 13, 2024
1 parent ad93686 commit 350cc03
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 36 deletions.
2 changes: 1 addition & 1 deletion benches/centralized_telescope/number_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn prove_steps(param: &BenchParam, truncate_size: u64, n: u64) -> u64 {
/// Run step benchmarks on list of parameters, varying the dataset the prover
/// generates a proof from. More particularly we change
/// - the dataset elements,
/// - the dataset cardinality, between `set_size` and `set_card`.
/// - the dataset cardinality, between `set_size` and `set_cardinality`.
fn step_benches(c: &mut Criterion<Steps>) {
benchmarks::<u64, u64, Steps>(
c,
Expand Down
8 changes: 4 additions & 4 deletions benches/centralized_telescope/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ fn proof_bench(params: &[BenchParam]) {
let params = Params {
soundness_param: param.lambda_sec,
completeness_param: param.lambda_rel,
set_size: param.set_size_per,
lower_bound: param.lower_bound_per,
set_size: param.set_size_percentage,
lower_bound: param.lower_bound_percentage,
};
let setup = init::make_setup(&params);
println!(
"{0: <23} | {1: <26} | {2: <14} | {3: <17} | {4: <14}",
param.lambda_sec,
param.lambda_rel,
param.set_size_per,
param.lower_bound_per,
param.set_size_percentage,
param.lower_bound_percentage,
setup.proof_size
);
}
Expand Down
2 changes: 1 addition & 1 deletion benches/centralized_telescope/proving_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn prove_duration(params: &BenchParam, truncate_size: u64, n: u64) -> Duration {
/// Run prove benchmarks on list of parameters, varying the dataset the prover
/// generates a proof from. More particularly we change
/// - the dataset elements,
/// - the dataset cardinality, between `set_size` and `set_card`.
/// - the dataset cardinality, between `set_size` and `set_cardinality`.
fn proving_benches(c: &mut Criterion) {
benchmarks::<Instant, Duration, WallTime>(
c,
Expand Down
10 changes: 5 additions & 5 deletions benches/centralized_telescope/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ pub const NAME: &str = "Centralized";
pub fn setup(rng: &mut ChaCha20Rng, params: &BenchParam) -> (Vec<[u8; 32]>, CentralizedTelescope) {
let seed_u32 = rng.next_u32();
let seed = seed_u32.to_ne_bytes().to_vec();
let dataset: Vec<[u8; 32]> = test_utils::gen_items(&seed, params.set_card);
let dataset: Vec<[u8; 32]> = test_utils::gen_items(&seed, params.set_cardinality);
let params = Params {
soundness_param: params.lambda_sec,
completeness_param: params.lambda_rel,
set_size: params
.set_size_per
.saturating_mul(params.set_card)
.set_size_percentage
.saturating_mul(params.set_cardinality)
.div_ceil(100),
lower_bound: params
.lower_bound_per
.saturating_mul(params.set_card)
.lower_bound_percentage
.saturating_mul(params.set_cardinality)
.div_ceil(100),
};
let telescope = CentralizedTelescope::create(&params);
Expand Down
2 changes: 1 addition & 1 deletion benches/centralized_telescope/verifying_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn verify_duration(params: &BenchParam, truncate_size: u64, n: u64) -> Duration
/// Run verify benchmarks on list of parameters, varying the dataset the prover
/// generates a proof from. More particularly we change
/// - the dataset elements,
/// - the dataset cardinality, between `set_size` and `set_card`.
/// - the dataset cardinality, between `set_size` and `set_cardinality`.
fn verify_benches(c: &mut Criterion) {
benchmarks::<Instant, Duration, WallTime>(
c,
Expand Down
32 changes: 17 additions & 15 deletions benches/common/criterion_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use criterion::{

pub mod centralized {
use super::{BenchmarkId, Criterion, Measurement};

/// Benchmark parameters
#[derive(Debug, Clone, Copy)]
pub struct BenchParam {
Expand All @@ -17,11 +16,11 @@ pub mod centralized {
/// Completeness Security parameter
pub lambda_rel: f64,
/// Alba's set cardinality (|Sp|)
pub set_card: u64,
pub set_cardinality: u64,
/// Alba's set_size (np) parameter in percentage of the set cardinality
pub set_size_per: u64,
pub set_size_percentage: u64,
/// Alba's lower bound (nf) parameter in percentage of the set cardinality
pub lower_bound_per: u64,
pub lower_bound_percentage: u64,
}

impl BenchParam {
Expand All @@ -33,10 +32,10 @@ pub mod centralized {
"params={{λsec:{}, λrel:{}, Sp:{} ({}%), n_p:{}, n_f:{}}}",
self.lambda_sec,
self.lambda_rel,
self.set_card,
self.set_cardinality,
pc,
self.set_size_per,
self.lower_bound_per
self.set_size_percentage,
self.lower_bound_percentage
),
)
}
Expand All @@ -57,23 +56,26 @@ pub mod centralized {
// Benchmark where the prover only has access to np percent elements of Sp,
// i.e. the minimum number of elements such that the soundness is lower than 2^-λ
let low = param
.set_card
.saturating_mul(param.set_size_per)
.set_cardinality
.saturating_mul(param.set_size_percentage)
.div_ceil(100);
group.bench_function(param.bench_id(bench_name, param.set_size_per), move |b| {
b.iter_custom(|n| f(param, low, n));
});
group.bench_function(
param.bench_id(bench_name, param.set_size_percentage),
move |b| {
b.iter_custom(|n| f(param, low, n));
},
);

// Benchmark where the prover only has access to (np+100)/2 percent elements of Sp
let mean = param.set_size_per.saturating_add(100).div_ceil(2);
let mid: u64 = param.set_card.saturating_add(low).div_ceil(2);
let mean = param.set_size_percentage.saturating_add(100).div_ceil(2);
let mid: u64 = param.set_cardinality.saturating_add(low).div_ceil(2);
group.bench_function(param.bench_id(bench_name, mean), move |b| {
b.iter_custom(|n| f(param, mid, n));
});

// Benchmark where the prover only has access to all elements of Sp
group.bench_function(param.bench_id(bench_name, 100), move |b| {
b.iter_custom(|n| f(param, param.set_card, n));
b.iter_custom(|n| f(param, param.set_cardinality, n));
});
}

Expand Down
18 changes: 9 additions & 9 deletions benches/common/test_vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ pub mod centralized {
const LOW_PARAM: BenchParam = BenchParam {
lambda_sec: 64.0,
lambda_rel: 64.0,
set_card: 1_000,
set_size_per: 90,
lower_bound_per: 60,
set_cardinality: 1_000,
set_size_percentage: 90,
lower_bound_percentage: 60,
};

/// This case corresponds to medium security requirements with more realistic set_size
const MID_PARAM: BenchParam = BenchParam {
lambda_sec: 80.0,
lambda_rel: 80.0,
set_card: 1_000,
set_size_per: 80,
lower_bound_per: 60,
set_cardinality: 1_000,
set_size_percentage: 80,
lower_bound_percentage: 60,
};

/// This case corresponds to high security requirements with more realistic set_size
const HIGH_PARAM: BenchParam = BenchParam {
lambda_sec: 128.0,
lambda_rel: 128.0,
set_card: 1_000,
set_size_per: 80,
lower_bound_per: 67,
set_cardinality: 1_000,
set_size_percentage: 80,
lower_bound_percentage: 67,
};

pub const SHORT_TESTS: &[BenchParam; 2] = &[LOW_PARAM, MID_PARAM];
Expand Down

0 comments on commit 350cc03

Please sign in to comment.