Skip to content

Commit

Permalink
Added load_trusted_setup benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomTr committed Oct 23, 2024
1 parent e703333 commit 3848cfa
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blst/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ harness = false
[[bench]]
name = "lincomb"
harness = false

[[bench]]
name = "trusted_setup"
harness = false
35 changes: 35 additions & 0 deletions blst/benches/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions kzg-bench/src/benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod kzg;
pub mod lincomb;
pub mod poly;
pub mod recover;
pub mod trusted_setup;
pub mod zero_poly;
43 changes: 43 additions & 0 deletions kzg-bench/src/benches/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -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<TFr> + G1GetFp<TG1Fp>,
TG2: G2,
TPoly: Poly<TFr>,
TFFTSettings: FFTSettings<TFr>,
TKZGSettings: KZGSettings<TFr, TG1, TG2, TFFTSettings, TPoly, TG1Fp, TG1Affine>,
TG1Fp: G1Fp,
TG1Affine: G1Affine<TG1, TG1Fp>,
>(
c: &mut Criterion,
load_trusted_setup_file: &dyn Fn(&str) -> Result<TKZGSettings, String>,
load_trusted_setup: &dyn Fn(&[u8], &[u8], &[u8]) -> Result<TKZGSettings, String>,

Check failure on line 20 in kzg-bench/src/benches/trusted_setup.rs

View workflow job for this annotation

GitHub Actions / kzg_ci

very complex type used. Consider factoring parts into `type` definitions

Check failure on line 20 in kzg-bench/src/benches/trusted_setup.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, blst)

very complex type used. Consider factoring parts into `type` definitions

Check failure on line 20 in kzg-bench/src/benches/trusted_setup.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks)

very complex type used. Consider factoring parts into `type` definitions

Check failure on line 20 in kzg-bench/src/benches/trusted_setup.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, constantine)

very complex type used. Consider factoring parts into `type` definitions
) {
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();
});
});
}
4 changes: 4 additions & 0 deletions rust-eth-kzg-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ parallel = ["rust_eth_kzg/multithreaded"]
[[bench]]
name = "eip_7594"
harness = false

[[bench]]
name = "trusted_setup"
harness = false
26 changes: 26 additions & 0 deletions rust-eth-kzg-benches/benches/trusted_setup.rs
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 3848cfa

Please sign in to comment.