From c7ec055f85686cb766023b0c86086c9cffde7414 Mon Sep 17 00:00:00 2001 From: Raphael Toledo Date: Tue, 21 Jan 2025 15:32:56 +0000 Subject: [PATCH] Benches/CentralizedTelescope: Adding proving steps bench --- Cargo.toml | 6 ++ benches/centralized_telescope/number_steps.rs | 72 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 benches/centralized_telescope/number_steps.rs diff --git a/Cargo.toml b/Cargo.toml index 88388fbe..39dacf96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benches/centralized_telescope/number_steps.rs b/benches/centralized_telescope/number_steps.rs new file mode 100644 index 00000000..d32d9f49 --- /dev/null +++ b/benches/centralized_telescope/number_steps.rs @@ -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, ¶ms, &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) { + benchmarks::( + 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);