Skip to content

Commit

Permalink
Benches/CentralizedTelescope: Adding proving steps bench
Browse files Browse the repository at this point in the history
  • Loading branch information
rrtoledo committed Jan 21, 2025
1 parent ca5887e commit c7ec055
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ name = "centralized_verifying_time"
harness = false
path = "benches/centralized_telescope/verifying_time.rs"

[[bench]]
name = "centralized_number_steps"
harness = false
path = "benches/centralized_telescope/number_steps.rs"


[lints.rust]
missing-copy-implementations = "warn"
missing-debug-implementations = "warn"
Expand Down
72 changes: 72 additions & 0 deletions benches/centralized_telescope/number_steps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//! Benchmarking the number of DFS calls, aka number of steps, of the
//! Centralized Telescope scheme
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rand_chacha::ChaCha20Rng;
use rand_core::SeedableRng;
use std::time::Duration;

mod utils;
use utils::{
common::{
criterion_helpers::{
centralized::{benchmarks, BenchParam},
Steps,
},
test_vectors::centralized::SHORT_TESTS,
},
setup, NAME,
};

use alba::centralized_telescope::proof::Proof;

/// Function benchmarking `sample_size` times the number of DFS calls, aka steps
#[allow(clippy::unit_arg)]
fn prove_steps(param: &BenchParam, truncate_size: u64, n: u64) -> u64 {
let mut rng = ChaCha20Rng::from_entropy();
let mut total_steps = 0u64;

// Setup
let (mut dataset, telescope) = setup(&mut rng, param);
let set_size = telescope.get_set_size();
let params = telescope.get_params();
// Truncate the dataset to give truncate_size elements to the prover
dataset.truncate(truncate_size as usize);

// Iterate on each sample `n` times
for _ in 0..n {
// Bench the number of steps/DFS calls while generating a proof
black_box({
let steps = Proof::bench(set_size, &params, &dataset).0;
total_steps = total_steps.saturating_add(steps);
});
}
total_steps
}

/// 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_cardinality`.
fn step_benches(c: &mut Criterion<Steps>) {
benchmarks::<u64, u64, Steps>(
c,
SHORT_TESTS,
format!("{} - {}", NAME, "Steps"),
"Prove",
&prove_steps,
);
}

mod criterion_group {
#![allow(missing_docs)]
use super::{criterion_group, step_benches, Criterion, Duration, Steps};
use crate::utils::common::criterion_helpers::{MEASUREMENT_TIME_SEC, SAMPLE_SIZE};

criterion_group!(name = centralized_step;
config = Criterion::default().with_measurement(Steps).measurement_time(Duration::from_secs(MEASUREMENT_TIME_SEC)).sample_size(SAMPLE_SIZE);
targets = step_benches
);
}

criterion_main!(criterion_group::centralized_step);

0 comments on commit c7ec055

Please sign in to comment.