Skip to content

Commit

Permalink
Add rs encode/decode benches (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielSanchezQ authored Nov 7, 2024
1 parent d73f3c2 commit 727b838
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nomos-da/kzgrs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ harness = false
name = "fk20"
harness = false


[[bench]]
name = "rs"
harness = false

[features]
default = ["single"]
single = []
Expand Down
54 changes: 54 additions & 0 deletions nomos-da/kzgrs/benches/rs.rs
Original file line number Diff line number Diff line change
@@ -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::<Fr>::new(size).unwrap();
let (_, poly) = bytes_to_polynomial::<31>(buff, domain).unwrap();
let domain = GeneralEvaluationDomain::<Fr>::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::<Fr>::new(size).unwrap();
let (_, poly) = bytes_to_polynomial::<31>(&buffer, domain).unwrap();
let domain = GeneralEvaluationDomain::<Fr>::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::<Fr>::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)
})
})
}

0 comments on commit 727b838

Please sign in to comment.