Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 64 additions & 0 deletions crates/prover/benches/barycentric_eval_at_point.rs
Original file line number Diff line number Diff line change
@@ -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<B: PolyOps>(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::<B, BaseField, BitReversedOrder>::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<B: PolyOps>(
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::<B, BaseField, BitReversedOrder>::barycentric_weights(
black_box(coset),
black_box(point),
)
});
},
);
}

fn barycentric_eval_at_secure_point_benches(c: &mut Criterion) {
bench_barycentric_eval_at_secure_point::<SimdBackend>(c, "simd");
bench_barycentric_eval_at_secure_point::<CpuBackend>(c, "cpu");
bench_barycentric_eval_at_secure_point_weights_calculation::<SimdBackend>(c, "simd");
bench_barycentric_eval_at_secure_point_weights_calculation::<CpuBackend>(c, "cpu");
}

criterion_group!(
name = benches;
config = Criterion::default().sample_size(10);
targets = barycentric_eval_at_secure_point_benches);
criterion_main!(benches);
Loading