diff --git a/blst/Cargo.toml b/blst/Cargo.toml index 284c9579..a2985d91 100644 --- a/blst/Cargo.toml +++ b/blst/Cargo.toml @@ -89,3 +89,7 @@ harness = false [[bench]] name = "lincomb" harness = false + +[[bench]] +name = "trusted_setup" +harness = false \ No newline at end of file diff --git a/blst/benches/trusted_setup.rs b/blst/benches/trusted_setup.rs new file mode 100644 index 00000000..6502ca88 --- /dev/null +++ b/blst/benches/trusted_setup.rs @@ -0,0 +1,35 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use kzg::eip_4844::load_trusted_setup_rust; +use kzg_bench::benches::trusted_setup::bench_load_trusted_setup; +use rust_kzg_blst::{ + eip_4844::load_trusted_setup_filename_rust, + types::{ + fft_settings::FsFFTSettings, + fp::FsFp, + fr::FsFr, + g1::{FsG1, FsG1Affine}, + g2::FsG2, + kzg_settings::FsKZGSettings, + poly::FsPoly, + }, +}; + +fn bench_load_trusted_setup_(c: &mut Criterion) { + bench_load_trusted_setup::< + FsFr, + FsG1, + FsG2, + FsPoly, + FsFFTSettings, + FsKZGSettings, + FsFp, + FsG1Affine, + >( + c, + &load_trusted_setup_filename_rust, + &load_trusted_setup_rust, + ); +} + +criterion_group!(benches, bench_load_trusted_setup_); +criterion_main!(benches); diff --git a/kzg-bench/src/benches/mod.rs b/kzg-bench/src/benches/mod.rs index 8d0f7f5b..1d14101f 100644 --- a/kzg-bench/src/benches/mod.rs +++ b/kzg-bench/src/benches/mod.rs @@ -7,4 +7,5 @@ pub mod kzg; pub mod lincomb; pub mod poly; pub mod recover; +pub mod trusted_setup; pub mod zero_poly; diff --git a/kzg-bench/src/benches/trusted_setup.rs b/kzg-bench/src/benches/trusted_setup.rs new file mode 100644 index 00000000..5c9d4a15 --- /dev/null +++ b/kzg-bench/src/benches/trusted_setup.rs @@ -0,0 +1,43 @@ +use criterion::Criterion; +use kzg::{ + eip_4844::TRUSTED_SETUP_PATH, FFTSettings, Fr, G1Affine, G1Fp, G1GetFp, G1Mul, KZGSettings, + Poly, G1, G2, +}; +use std::{fs::File, io::Read, path::PathBuf}; + +pub fn bench_load_trusted_setup< + TFr: Fr + std::fmt::Debug, + TG1: G1 + G1Mul + G1GetFp, + TG2: G2, + TPoly: Poly, + TFFTSettings: FFTSettings, + TKZGSettings: KZGSettings, + TG1Fp: G1Fp, + TG1Affine: G1Affine, +>( + c: &mut Criterion, + load_trusted_setup_file: &dyn Fn(&str) -> Result, + load_trusted_setup: &dyn Fn(&[u8], &[u8], &[u8]) -> Result, +) { + let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(TRUSTED_SETUP_PATH) + .to_string_lossy() + .to_string(); + + c.bench_function("load_trusted_setup_file", |b| { + b.iter(|| { + let _ = load_trusted_setup_file(path.as_str()).unwrap(); + }); + }); + + c.bench_function("load_trusted_setup", |b| { + let mut file = File::open(path.clone()).unwrap(); + let mut source = String::new(); + file.read_to_string(&mut source).unwrap(); + let bytes = kzg::eip_4844::load_trusted_setup_string(source.as_str()).unwrap(); + + b.iter(|| { + let _ = load_trusted_setup(&bytes.0, &bytes.1, &bytes.2).unwrap(); + }); + }); +} diff --git a/rust-eth-kzg-benches/Cargo.toml b/rust-eth-kzg-benches/Cargo.toml index 35192ce4..3626dd6b 100644 --- a/rust-eth-kzg-benches/Cargo.toml +++ b/rust-eth-kzg-benches/Cargo.toml @@ -18,3 +18,7 @@ parallel = ["rust_eth_kzg/multithreaded"] [[bench]] name = "eip_7594" harness = false + +[[bench]] +name = "trusted_setup" +harness = false diff --git a/rust-eth-kzg-benches/benches/trusted_setup.rs b/rust-eth-kzg-benches/benches/trusted_setup.rs new file mode 100644 index 00000000..c04f1dc1 --- /dev/null +++ b/rust-eth-kzg-benches/benches/trusted_setup.rs @@ -0,0 +1,26 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use rust_eth_kzg::{DASContext, TrustedSetup, UsePrecomp}; + +fn bench_load_trusted_setup( + c: &mut Criterion +) { + c.bench_function("load_trusted_setup", |b| { + + b.iter(|| { + let trusted_setup = TrustedSetup::default(); + + #[cfg(feature = "parallel")] + let _ = DASContext::with_threads( + &trusted_setup, + rust_eth_kzg::ThreadCount::Multi(std::thread::available_parallelism().unwrap().into()), + UsePrecomp::Yes { width: 8 }, + ); + + #[cfg(not(feature = "parallel"))] + let _ = DASContext::new(&trusted_setup, UsePrecomp::Yes { width: 8 }); + }); + }); +} + +criterion_group!(benches, bench_load_trusted_setup); +criterion_main!(benches);