Skip to content

Commit

Permalink
fix: iterate coz bench code many times
Browse files Browse the repository at this point in the history
  • Loading branch information
alxiong committed Jun 15, 2023
1 parent 6a8644a commit 4b4827d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand All @@ -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 = [
Expand Down
30 changes: 30 additions & 0 deletions primitives/benches/reed_solomon_coz.rs
Original file line number Diff line number Diff line change
@@ -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: <https://github.com/plasma-umass/coz/issues/158#issuecomment-708507510>
const ITERATIONS: usize = 2_000_000_000;

fn main() {
coz::thread_init();

let domain = GeneralEvaluationDomain::<Fr254>::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::<Vec<_>>();

// decode
for _ in 0..ITERATIONS {
reed_solomon_erasure_decode::<Fr254, _, _, _>(
eval_points.iter().zip(&code).take(N_HALF),
N_HALF,
)
.unwrap();
}
}
3 changes: 0 additions & 3 deletions primitives/src/reed_solomon_code/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 4b4827d

Please sign in to comment.