Fix blob size in encoder bench

This commit is contained in:
danielsanchezq 2024-06-27 17:48:56 +02:00
parent 3fef984fe9
commit ee66796db5
1 changed files with 12 additions and 12 deletions

View File

@ -1,7 +1,6 @@
use divan::counter::BytesCount;
use divan::Bencher;
use kzgrs_backend::encoder::{DaEncoder, DaEncoderParams};
use once_cell::sync::Lazy;
use rand::RngCore;
use std::hint::black_box;
@ -9,22 +8,23 @@ fn main() {
divan::main()
}
static ENCODER: Lazy<DaEncoder> = Lazy::new(|| {
let params = DaEncoderParams::new(4096, true);
DaEncoder::new(params)
});
const KB: usize = 1024;
const MB1: usize = 1024 * 1024;
pub fn rand_data(elements_count: usize) -> Vec<u8> {
let mut buff = vec![0; elements_count * DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE];
rand::thread_rng().fill_bytes(&mut buff);
buff
}
#[divan::bench(args = [32, 64, 128, 256, 512, 1024, 2048], sample_count = 1, sample_size = 1)]
fn encode(bencher: Bencher, size: usize) {
#[divan::bench(args = [128, 256, 512, 1024, 2048, 4096], sample_count = 1, sample_size = 1)]
fn encode(bencher: Bencher, column_size: usize) {
bencher
.with_inputs(|| rand_data(size * KB / DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE))
.input_counter(|buff| BytesCount::new(buff.len()))
.bench_refs(|buff| black_box(ENCODER.encode(buff)));
.with_inputs(|| {
let params = DaEncoderParams::new(column_size, true);
(
DaEncoder::new(params),
rand_data(MB1 / DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE),
)
})
.input_counter(|(_, buff)| BytesCount::new(buff.len()))
.bench_refs(|(encoder, buff)| black_box(encoder.encode(buff)));
}