diff --git a/crates/prover/Cargo.toml b/crates/prover/Cargo.toml index 03e99ae28..64f17c92c 100644 --- a/crates/prover/Cargo.toml +++ b/crates/prover/Cargo.toml @@ -66,6 +66,10 @@ name = "bit_rev" harness = false name = "eval_at_point" +[[bench]] +harness = false +name = "barycentric_eval_at_point" + [[bench]] harness = false name = "fft" diff --git a/crates/prover/benches/barycentric_eval_at_point.rs b/crates/prover/benches/barycentric_eval_at_point.rs new file mode 100644 index 000000000..a87289cda --- /dev/null +++ b/crates/prover/benches/barycentric_eval_at_point.rs @@ -0,0 +1,64 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use rand::rngs::SmallRng; +use rand::{Rng, SeedableRng}; +use stwo_prover::core::backend::cpu::CpuBackend; +use stwo_prover::core::backend::simd::SimdBackend; +use stwo_prover::core::circle::CirclePoint; +use stwo_prover::core::fields::m31::BaseField; +use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation, CirclePoly, PolyOps}; +use stwo_prover::core::poly::BitReversedOrder; + +const LOG_SIZE: u32 = 20; + +fn bench_barycentric_eval_at_secure_point(c: &mut Criterion, id: &str) { + let poly = CirclePoly::new((0..1 << LOG_SIZE).map(BaseField::from).collect()); + let coset = CanonicCoset::new(LOG_SIZE); + let evals = poly.evaluate(coset.circle_domain()); + let mut rng = SmallRng::seed_from_u64(0); + let x = rng.gen(); + let y = rng.gen(); + let point = CirclePoint { x, y }; + let weights = + CircleEvaluation::::barycentric_weights(coset, point); + c.bench_function( + &format!("{id} barycentric_eval_at_secure_field_point 2^{LOG_SIZE}"), + |b| { + b.iter(|| B::barycentric_eval_at_point(black_box(&evals), black_box(&weights))); + }, + ); +} + +fn bench_barycentric_eval_at_secure_point_weights_calculation( + c: &mut Criterion, + id: &str, +) { + let mut rng = SmallRng::seed_from_u64(0); + let x = rng.gen(); + let y = rng.gen(); + let point = CirclePoint { x, y }; + let coset = CanonicCoset::new(LOG_SIZE); + c.bench_function( + &format!("{id} barycentric_eval_at_secure_point_weights_calculation 2^{LOG_SIZE}"), + |b| { + b.iter(|| { + CircleEvaluation::::barycentric_weights( + black_box(coset), + black_box(point), + ) + }); + }, + ); +} + +fn barycentric_eval_at_secure_point_benches(c: &mut Criterion) { + bench_barycentric_eval_at_secure_point::(c, "simd"); + bench_barycentric_eval_at_secure_point::(c, "cpu"); + bench_barycentric_eval_at_secure_point_weights_calculation::(c, "simd"); + bench_barycentric_eval_at_secure_point_weights_calculation::(c, "cpu"); +} + +criterion_group!( + name = benches; + config = Criterion::default().sample_size(10); + targets = barycentric_eval_at_secure_point_benches); +criterion_main!(benches);