2024-06-25 13:39:40 +00:00
|
|
|
use divan::counter::BytesCount;
|
|
|
|
use divan::Bencher;
|
|
|
|
use kzgrs_backend::encoder::{DaEncoder, DaEncoderParams};
|
2024-10-08 16:39:38 +00:00
|
|
|
use kzgrs_backend::global::GLOBAL_PARAMETERS;
|
2024-06-25 13:39:40 +00:00
|
|
|
use rand::RngCore;
|
|
|
|
use std::hint::black_box;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
divan::main()
|
|
|
|
}
|
|
|
|
|
2024-07-03 10:55:05 +00:00
|
|
|
const MB: usize = 1024;
|
2024-06-25 13:39:40 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2024-07-03 10:55:05 +00:00
|
|
|
#[divan::bench(consts = [32, 64, 128, 256, 512, 1024], args = [128, 256, 512, 1024, 2048, 4096], sample_count = 1, sample_size = 1)]
|
|
|
|
fn encode<const SIZE: usize>(bencher: Bencher, column_size: usize) {
|
2024-06-25 13:39:40 +00:00
|
|
|
bencher
|
2024-07-01 08:54:48 +00:00
|
|
|
.with_inputs(|| {
|
2024-10-08 16:39:38 +00:00
|
|
|
let params = DaEncoderParams::new(column_size, true, GLOBAL_PARAMETERS.clone());
|
2024-07-01 08:54:48 +00:00
|
|
|
(
|
|
|
|
DaEncoder::new(params),
|
2024-07-03 10:55:05 +00:00
|
|
|
rand_data(SIZE * MB / DaEncoderParams::MAX_BLS12_381_ENCODING_CHUNK_SIZE),
|
2024-07-01 08:54:48 +00:00
|
|
|
)
|
|
|
|
})
|
|
|
|
.input_counter(|(_, buff)| BytesCount::new(buff.len()))
|
2024-08-02 17:01:18 +00:00
|
|
|
.bench_refs(|(encoder, buff)| black_box(nomos_core::da::DaEncoder::encode(encoder, buff)));
|
2024-06-25 13:39:40 +00:00
|
|
|
}
|