diff --git a/nomos-da/kzgrs/Cargo.toml b/nomos-da/kzgrs/Cargo.toml index 06a36c1d..00dbcd3e 100644 --- a/nomos-da/kzgrs/Cargo.toml +++ b/nomos-da/kzgrs/Cargo.toml @@ -30,6 +30,10 @@ divan = "0.1" name = "kzg" harness = false +[[bench]] +name = "fft" +harness = false + [features] default = ["single"] single = [] diff --git a/nomos-da/kzgrs/benches/fft.rs b/nomos-da/kzgrs/benches/fft.rs new file mode 100644 index 00000000..549f6f2a --- /dev/null +++ b/nomos-da/kzgrs/benches/fft.rs @@ -0,0 +1,52 @@ +use ark_bls12_381::{Fr, G1Affine}; +use ark_ec::{AffineRepr, CurveGroup}; +use ark_ff::{BigInt, FftField, Field}; +use divan::counter::ItemsCount; +use divan::{black_box, counter::BytesCount, AllocProfiler, Bencher}; +use kzgrs::fft::{fft_g1, ifft_g1}; +fn main() { + divan::main() +} + +#[divan::bench(args = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096])] +fn compute_fft_for_size(bencher: Bencher, size: usize) { + bencher + .with_inputs(|| { + let primitive_root = ::get_root_of_unity(size as u64).unwrap(); + let roots_of_unity: Vec<_> = (1..=size) + .map(|i| primitive_root.pow::>(BigInt::from(i as u64))) + .collect(); + let buff: Vec = (0..size) + .map(|i| { + G1Affine::identity() + .mul_bigint(BigInt::<4>::from(i as u64)) + .into_affine() + }) + .collect(); + (buff, roots_of_unity) + }) + .input_counter(|_| ItemsCount::new(size)) + .bench_refs(|(buff, roots_of_unity)| black_box(fft_g1(buff, roots_of_unity))); +} + +#[divan::bench(args = [16, 32, 64, 128, 256, 512, 1024, 2048, 4096])] +fn compute_ifft_for_size(bencher: Bencher, size: usize) { + bencher + .with_inputs(|| { + let primitive_root = ::get_root_of_unity(size as u64).unwrap(); + let roots_of_unity: Vec<_> = (1..=size) + .map(|i| primitive_root.pow::>(BigInt::from(i as u64))) + .collect(); + let buff: Vec = (0..size) + .map(|i| { + G1Affine::identity() + .mul_bigint(BigInt::<4>::from(i as u64)) + .into_affine() + }) + .collect(); + let buff = fft_g1(&buff, &roots_of_unity); + (buff, roots_of_unity) + }) + .input_counter(|_| ItemsCount::new(size)) + .bench_refs(|(buff, roots_of_unity)| black_box(ifft_g1(buff, roots_of_unity))); +} diff --git a/nomos-da/kzgrs/src/lib.rs b/nomos-da/kzgrs/src/lib.rs index 833d959f..72ab52f8 100644 --- a/nomos-da/kzgrs/src/lib.rs +++ b/nomos-da/kzgrs/src/lib.rs @@ -1,6 +1,6 @@ pub mod common; -mod fft; -mod fk20; +pub mod fft; +pub mod fk20; pub mod global_parameters; pub mod kzg; pub mod rs;