Skip to content
Snippets Groups Projects

benchmark the recoding process

Merged STEVAN Antoine requested to merge bench-recoding into main
1 file
+ 24
15
Compare changes
  • Side-by-side
  • Inline
+ 24
15
@@ -4,24 +4,26 @@ use ark_ff::PrimeField;
@@ -4,24 +4,26 @@ use ark_ff::PrimeField;
use rand::Rng;
use rand::Rng;
use komodo::{fec::Shard, field};
use komodo::{
 
fec::{combine, Shard},
 
field,
 
};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, Criterion};
fn to_curve<E: Pairing>(n: u128) -> E::ScalarField {
fn to_curve<E: Pairing>(n: u128) -> E::ScalarField {
E::ScalarField::from_le_bytes_mod_order(&n.to_le_bytes())
E::ScalarField::from_le_bytes_mod_order(&n.to_le_bytes())
}
}
fn create_fake_shard<E: Pairing>(nb_bytes: usize, nb_shards: usize) -> Shard<E> {
fn create_fake_shard<E: Pairing>(nb_bytes: usize, k: usize) -> Shard<E> {
let mut rng = rand::thread_rng();
let mut rng = rand::thread_rng();
let bytes: Vec<u8> = (0..nb_bytes).map(|_| rng.gen::<u8>()).collect();
let bytes: Vec<u8> = (0..nb_bytes).map(|_| rng.gen::<u8>()).collect();
let linear_combination: Vec<E::ScalarField> = (0..nb_bytes)
let linear_combination: Vec<E::ScalarField> =
.map(|_| to_curve::<E>(rng.gen::<u128>()))
(0..k).map(|_| to_curve::<E>(rng.gen::<u128>())).collect();
.collect();
Shard {
Shard {
k: nb_shards as u32,
k: k as u32,
linear_combination,
linear_combination,
hash: vec![],
hash: vec![],
bytes: field::split_data_into_field_elements::<E>(&bytes, 1),
bytes: field::split_data_into_field_elements::<E>(&bytes, 1),
@@ -29,24 +31,31 @@ fn create_fake_shard<E: Pairing>(nb_bytes: usize, nb_shards: usize) -> Shard<E>
@@ -29,24 +31,31 @@ fn create_fake_shard<E: Pairing>(nb_bytes: usize, nb_shards: usize) -> Shard<E>
}
}
}
}
fn bench_template<E: Pairing>(c: &mut Criterion, nb_bytes: usize, nb_shards: usize) {
fn bench_template<E: Pairing>(c: &mut Criterion, nb_bytes: usize, k: usize, nb_shards: usize) {
let b1: Shard<E> = create_fake_shard(nb_bytes, nb_shards);
let shards: Vec<Shard<E>> = (0..nb_shards)
let b2: Shard<E> = create_fake_shard(nb_bytes, nb_shards);
.map(|_| create_fake_shard(nb_bytes, k))
 
.collect();
let mut rng = rand::thread_rng();
let mut rng = rand::thread_rng();
let alpha = to_curve::<E>(black_box(rng.gen::<u128>()));
let coeffs: Vec<E::ScalarField> = (0..nb_shards)
let beta = to_curve::<E>(black_box(rng.gen::<u128>()));
.map(|_| to_curve::<E>(rng.gen::<u128>()))
 
.collect();
c.bench_function(
c.bench_function(
&format!("recoding {} bytes and {} shards", nb_bytes, nb_shards),
&format!(
|b| b.iter(|| b1.combine(alpha, &b2, beta)),
"recoding {} bytes and {} shards with k = {}",
 
nb_bytes, nb_shards, k
 
),
 
|b| b.iter(|| combine(&shards, &coeffs)),
);
);
}
}
pub fn criterion_benchmark(c: &mut Criterion) {
pub fn criterion_benchmark(c: &mut Criterion) {
for nb_bytes in [1, 1_024, 1_024 * 1_024] {
for nb_bytes in [1, 1_024, 1_024 * 1_024] {
for nb_shards in [2, 4, 8, 16] {
for nb_shards in [2, 4, 8, 16] {
bench_template::<Bls12_381>(c, nb_bytes, nb_shards);
for k in [2, 4, 8, 16] {
 
bench_template::<Bls12_381>(c, nb_bytes, k, nb_shards);
 
}
}
}
}
}
}
}
Loading