From a0c975f9aac03a2a500d5664d5b2754e8e6ca686 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Quiros Date: Fri, 26 Apr 2024 17:52:24 +0200 Subject: [PATCH] Added rs encoding and proofs generation benchmarks --- nomos-da/kzgrs-backend/benches/encode.rs | 45 ++++++++++++++++++++++++ nomos-da/kzgrs-backend/src/encoder.rs | 4 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/nomos-da/kzgrs-backend/benches/encode.rs b/nomos-da/kzgrs-backend/benches/encode.rs index 84e91ae2..3cc0c4e4 100644 --- a/nomos-da/kzgrs-backend/benches/encode.rs +++ b/nomos-da/kzgrs-backend/benches/encode.rs @@ -1,4 +1,6 @@ +use divan::counter::ItemsCount; use divan::{black_box, counter::BytesCount, AllocProfiler, Bencher}; +use kzgrs::{Evaluations, Polynomial}; use rand::RngCore; use kzgrs_backend::encoder::{DaEncoder, DaEncoderParams}; @@ -58,6 +60,49 @@ fn compute_1MB_data_matrix_kzg_row_commitments_with_column_count( .bench_refs(|matrix| black_box(DaEncoder::compute_kzg_row_commitments(&matrix).is_ok())); } +#[allow(non_snake_case)] +#[divan::bench(args = [100, 1000, 10000], sample_count = 1, sample_size = 1)] +fn compute_1MB_data_rs_encode_rows_with_column_count(bencher: Bencher, column_count: usize) { + let encoder_params: DaEncoderParams = DaEncoderParams::default_with(column_count); + let encoder: DaEncoder = DaEncoder::new(encoder_params); + let size = bencher + .with_inputs(|| { + let matrix = encoder.chunkify(rand_data(1).as_ref()); + let (row_polynomials, _): (Vec<(Evaluations, Polynomial)>, Vec<_>) = + DaEncoder::compute_kzg_row_commitments(&matrix) + .unwrap() + .into_iter() + .unzip(); + row_polynomials + }) + .input_counter(|polynomials| ItemsCount::new(polynomials.len())) + .bench_refs(|polynomials| black_box(DaEncoder::rs_encode_rows(polynomials))); +} + +#[allow(non_snake_case)] +#[divan::bench(args = [100, 1000, 10000], sample_count = 1, sample_size = 1)] +fn compute_1MB_data_compute_rows_proofs_with_column_count(bencher: Bencher, column_count: usize) { + let encoder_params: DaEncoderParams = DaEncoderParams::default_with(column_count); + let encoder: DaEncoder = DaEncoder::new(encoder_params); + let size = bencher + .with_inputs(|| { + let matrix = encoder.chunkify(rand_data(1).as_ref()); + let (row_polynomials, _): (Vec<(Evaluations, Polynomial)>, Vec<_>) = + DaEncoder::compute_kzg_row_commitments(&matrix) + .unwrap() + .into_iter() + .unzip(); + row_polynomials + .into_iter() + .map(|(_, poly)| poly) + .collect::>() + }) + .input_counter(|polynomials| ItemsCount::new(polynomials.len())) + .bench_refs(|polynomials| { + black_box(DaEncoder::compute_rows_proofs(polynomials, column_count).is_ok()) + }); +} + #[allow(non_snake_case)] #[divan::bench(args = [100, 1000, 10000], sample_count = 1, sample_size = 1)] fn encode_1MB_with_column_count(bencher: Bencher, column_count: usize) { diff --git a/nomos-da/kzgrs-backend/src/encoder.rs b/nomos-da/kzgrs-backend/src/encoder.rs index 23553f1b..6149a72d 100644 --- a/nomos-da/kzgrs-backend/src/encoder.rs +++ b/nomos-da/kzgrs-backend/src/encoder.rs @@ -89,13 +89,13 @@ impl DaEncoder { encode(row, evaluations, 2, *DOMAIN) } - fn rs_encode_rows(rows: &[(Evaluations, Polynomial)]) -> Vec { + pub fn rs_encode_rows(rows: &[(Evaluations, Polynomial)]) -> Vec { rows.iter() .map(|(eval, poly)| Self::rs_encode_row(eval, poly)) .collect() } - fn compute_rows_proofs( + pub fn compute_rows_proofs( polynomials: &[Polynomial], proof_count: usize, ) -> Result>, KzgRsError> {