Skip to content

Commit 433ac65

Browse files
Barycentric Evaluation Bench
1 parent 8daa3b4 commit 433ac65

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

crates/prover/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ name = "bit_rev"
6666
harness = false
6767
name = "eval_at_point"
6868

69+
[[bench]]
70+
harness = false
71+
name = "barycentric_eval_at_point"
72+
6973
[[bench]]
7074
harness = false
7175
name = "fft"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use rand::rngs::SmallRng;
3+
use rand::{Rng, SeedableRng};
4+
use stwo_prover::core::backend::cpu::CpuBackend;
5+
use stwo_prover::core::backend::simd::SimdBackend;
6+
use stwo_prover::core::circle::CirclePoint;
7+
use stwo_prover::core::fields::m31::BaseField;
8+
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation, CirclePoly, PolyOps};
9+
use stwo_prover::core::poly::BitReversedOrder;
10+
11+
const LOG_SIZE: u32 = 20;
12+
13+
fn bench_barycentric_eval_at_secure_point<B: PolyOps>(c: &mut Criterion, id: &str) {
14+
let poly = CirclePoly::new((0..1 << LOG_SIZE).map(BaseField::from).collect());
15+
let evals = poly.evaluate(CanonicCoset::new(LOG_SIZE).circle_domain());
16+
let mut rng = SmallRng::seed_from_u64(0);
17+
let x = rng.gen();
18+
let y = rng.gen();
19+
let point = CirclePoint { x, y };
20+
let weights = CircleEvaluation::<B, BaseField, BitReversedOrder>::weights(LOG_SIZE, point);
21+
c.bench_function(
22+
&format!("{id} barycentric_eval_at_secure_field_point 2^{LOG_SIZE}"),
23+
|b| {
24+
b.iter(|| {
25+
B::barycentric_eval_at_point(
26+
black_box(&evals),
27+
black_box(point),
28+
black_box(&weights),
29+
)
30+
});
31+
},
32+
);
33+
}
34+
35+
fn bench_barycentric_eval_at_secure_point_weights_calculation<B: PolyOps>(
36+
c: &mut Criterion,
37+
id: &str,
38+
) {
39+
let mut rng = SmallRng::seed_from_u64(0);
40+
let x = rng.gen();
41+
let y = rng.gen();
42+
let point = CirclePoint { x, y };
43+
c.bench_function(
44+
&format!("{id} barycentric_eval_at_secure_point_weights_calculation 2^{LOG_SIZE}"),
45+
|b| {
46+
b.iter(|| {
47+
CircleEvaluation::<B, BaseField, BitReversedOrder>::weights(
48+
black_box(LOG_SIZE),
49+
black_box(point),
50+
)
51+
});
52+
},
53+
);
54+
}
55+
56+
fn barycentric_eval_at_secure_point_benches(c: &mut Criterion) {
57+
bench_barycentric_eval_at_secure_point::<SimdBackend>(c, "simd");
58+
bench_barycentric_eval_at_secure_point::<CpuBackend>(c, "cpu");
59+
bench_barycentric_eval_at_secure_point_weights_calculation::<SimdBackend>(c, "simd");
60+
bench_barycentric_eval_at_secure_point_weights_calculation::<CpuBackend>(c, "cpu");
61+
}
62+
63+
criterion_group!(
64+
name = benches;
65+
config = Criterion::default().sample_size(10);
66+
targets = barycentric_eval_at_secure_point_benches);
67+
criterion_main!(benches);

0 commit comments

Comments
 (0)