diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 355345381..ec0fc82db 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -64,6 +64,7 @@ ark-ed-on-bls12-377 = "0.4.0" ark-ed-on-bls12-381-bandersnatch = "0.4.0" ark-ed-on-bn254 = "0.4.0" bincode = "1.3" +coz = "0.1" criterion = "0.4.0" sha2 = { version = "0.10.1" } @@ -80,6 +81,10 @@ name = "reed-solomon" path = "benches/reed_solomon.rs" harness = false +[[bench]] +name = "reed-solomon-coz" +path = "benches/reed_solomon_coz.rs" + [features] default = ["parallel"] std = [ diff --git a/primitives/benches/reed_solomon_coz.rs b/primitives/benches/reed_solomon_coz.rs new file mode 100644 index 000000000..6334b9fe1 --- /dev/null +++ b/primitives/benches/reed_solomon_coz.rs @@ -0,0 +1,30 @@ +//! Benchmark code for reed_solomon implementation for coz profiler. +use ark_bn254::Fr as Fr254; +use ark_poly::{EvaluationDomain, GeneralEvaluationDomain}; +use jf_primitives::reed_solomon_code::reed_solomon_erasure_decode; + +const N: usize = 2048; +const N_HALF: usize = 1024; +// run it many times so coz will be triggered enough times +// see: +const ITERATIONS: usize = 2_000_000_000; + +fn main() { + coz::thread_init(); + + let domain = GeneralEvaluationDomain::::new(N).unwrap(); + let input = vec![Fr254::from(1u64); N_HALF]; + + // encode and evaluate + let code = domain.fft(&input); + let eval_points = domain.elements().collect::>(); + + // decode + for _ in 0..ITERATIONS { + reed_solomon_erasure_decode::( + eval_points.iter().zip(&code).take(N_HALF), + N_HALF, + ) + .unwrap(); + } +} diff --git a/primitives/src/reed_solomon_code/mod.rs b/primitives/src/reed_solomon_code/mod.rs index e87dc6ac9..a161dd7f7 100644 --- a/primitives/src/reed_solomon_code/mod.rs +++ b/primitives/src/reed_solomon_code/mod.rs @@ -116,7 +116,6 @@ where #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] { coz::end!("computing l(X)"); - coz::progress!("finish l(X)"); coz::begin!("computing barycentric weight w_i"); } // Calculate the barycentric weight w_i @@ -141,7 +140,6 @@ where #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] { coz::end!("computing barycentric weight w_i"); - coz::progress!("finish w_i"); coz::begin!("computing f(X)"); } // Calculate f(x) = \sum_i l_i(x) @@ -161,7 +159,6 @@ where #[cfg(all(debug_assertions, target_os = "linux", feature = "profiling"))] { coz::end!("computing f(X)"); - coz::progress!("finish f(X)"); } Ok(f) }