From 727b838042e754b1c909c3ec53517c358b53639f Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Thu, 7 Nov 2024 05:17:54 +0100 Subject: [PATCH] Add rs encode/decode benches (#907) --- nomos-da/kzgrs/Cargo.toml | 5 ++++ nomos-da/kzgrs/benches/rs.rs | 54 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 nomos-da/kzgrs/benches/rs.rs diff --git a/nomos-da/kzgrs/Cargo.toml b/nomos-da/kzgrs/Cargo.toml index 3c004123c..83e074363 100644 --- a/nomos-da/kzgrs/Cargo.toml +++ b/nomos-da/kzgrs/Cargo.toml @@ -39,6 +39,11 @@ harness = false name = "fk20" harness = false + +[[bench]] +name = "rs" +harness = false + [features] default = ["single"] single = [] diff --git a/nomos-da/kzgrs/benches/rs.rs b/nomos-da/kzgrs/benches/rs.rs new file mode 100644 index 000000000..3ed0ff81f --- /dev/null +++ b/nomos-da/kzgrs/benches/rs.rs @@ -0,0 +1,54 @@ +use ark_bls12_381::Fr; +use ark_poly::{EvaluationDomain, GeneralEvaluationDomain}; +use kzgrs::common::bytes_to_polynomial; +use kzgrs::rs::*; + +use divan::counter::BytesCount; +use divan::{black_box, Bencher}; +use rand::{thread_rng, RngCore}; + +fn main() { + divan::main() +} + +#[divan::bench(args = [3224])] +fn rs_encode(bencher: Bencher, size: usize) { + bencher + .with_inputs(move || { + let mut buffer = vec![0u8; size]; + thread_rng().fill_bytes(&mut buffer); + buffer + }) + .input_counter(move |buff| BytesCount::new(buff.len())) + .bench_refs(|buff| { + let domain = GeneralEvaluationDomain::::new(size).unwrap(); + let (_, poly) = bytes_to_polynomial::<31>(buff, domain).unwrap(); + let domain = GeneralEvaluationDomain::::new(size * 2).unwrap(); + black_box(move || encode(&poly, domain)) + }) +} + +#[divan::bench(args = [3224], sample_size = 10, sample_count = 100)] +fn rs_decode(bencher: Bencher, size: usize) { + bencher + .with_inputs(move || { + let mut buffer = vec![0u8; size]; + thread_rng().fill_bytes(&mut buffer); + let domain = GeneralEvaluationDomain::::new(size).unwrap(); + let (_, poly) = bytes_to_polynomial::<31>(&buffer, domain).unwrap(); + let domain = GeneralEvaluationDomain::::new(size * 2).unwrap(); + let encoded = encode(&poly, domain); + encoded + }) + .input_counter(move |_buff| BytesCount::new(size * 31)) + .bench_values(|buff| { + black_box(move || { + let domain = GeneralEvaluationDomain::::new(size).unwrap(); + let missing_data: Vec<_> = std::iter::repeat(None) + .take(size) + .chain(buff.evals[size..].iter().copied().map(Some)) + .collect(); + decode(size, &missing_data, domain) + }) + }) +}