Skip to content

Commit 519a07b

Browse files
committed
Update benchmarks
1 parent 3274527 commit 519a07b

File tree

2 files changed

+51
-22
lines changed

2 files changed

+51
-22
lines changed

benches/fftree.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
use ark_serialize::CanonicalDeserialize;
2+
use ark_serialize::CanonicalSerialize;
13
use criterion::criterion_group;
24
use criterion::criterion_main;
35
use criterion::BenchmarkId;
46
use criterion::Criterion;
57
use ecfft::m31;
68
use ecfft::secp256k1;
9+
use ecfft::FFTree;
710
use ecfft::FftreeField;
811
use rand::rngs::StdRng;
912
use rand::SeedableRng;
@@ -63,9 +66,43 @@ fn bench_fftree<F: FftreeField>(c: &mut Criterion, field_description: &str) {
6366
group.sample_size(10);
6467

6568
for n in BENCHMARK_INPUT_SIZES {
69+
let fftree = F::build_fftree(n).unwrap();
70+
6671
group.bench_with_input(BenchmarkId::new("generate", n), &n, |b, _| {
6772
b.iter(|| F::build_fftree(n).unwrap())
6873
});
74+
75+
group.bench_with_input(BenchmarkId::new("serialize compressed", n), &n, |b, _| {
76+
b.iter(|| {
77+
let mut bytes = Vec::new();
78+
fftree.serialize_compressed(&mut bytes).unwrap();
79+
bytes
80+
})
81+
});
82+
83+
group.bench_with_input(BenchmarkId::new("serialize uncompressed", n), &n, |b, _| {
84+
b.iter(|| {
85+
let mut bytes = Vec::new();
86+
fftree.serialize_uncompressed(&mut bytes).unwrap();
87+
bytes
88+
})
89+
});
90+
91+
group.bench_with_input(BenchmarkId::new("deserialize compressed", n), &n, |b, _| {
92+
let mut bytes = Vec::new();
93+
fftree.serialize_compressed(&mut bytes).unwrap();
94+
b.iter(|| FFTree::<F>::deserialize_compressed(&*bytes).unwrap())
95+
});
96+
97+
group.bench_with_input(
98+
BenchmarkId::new("deserialize uncompressed", n),
99+
&n,
100+
|b, _| {
101+
let mut bytes = Vec::new();
102+
fftree.serialize_uncompressed(&mut bytes).unwrap();
103+
b.iter(|| FFTree::<F>::deserialize_uncompressed(&*bytes).unwrap())
104+
},
105+
);
69106
}
70107

71108
group.finish();

src/fftree.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<F: Field> FFTree<F> {
7777
f[n..].copy_from_slice(&leaves);
7878

7979
// generate internal nodes
80-
// TODO: use array_windows_mut
80+
// TODO: would be cool to use array_windows_mut
8181
let mut f_layers = f.get_layers_mut();
8282
for (i, rational_map) in rational_maps.iter().enumerate() {
8383
let (prev_layer, layer) = {
@@ -95,16 +95,6 @@ impl<F: Field> FFTree<F> {
9595
Self::from_tree(f, rational_maps)
9696
}
9797

98-
/// Decomposes evaluation table <P(X) ≀ S> into <P_0(X) ≀ T> and
99-
/// <P_1(X) ≀ T> where T = ψ(S), ψ(X) = u(X)/v(X) and
100-
/// P(s) = (P_0(ψ(s)) + s * P_1(ψ(s))) * v(s)^(d/2 - 1)
101-
// pub fn decompose(&self, evals: &[F], moiety: Moiety) -> (Vec<F>, Vec<F>) {}
102-
103-
// /// Recombines evaluation tables <P_0(X) ≀ T> and <P_1(X) ≀ T> to produce
104-
// /// <P(X) ≀ S> where ψ(X) = u(X)/v(X), T = ψ(S) and
105-
// /// P(s) = (P_0(ψ(s)) + s * P_1(ψ(s)) * v(s)^(d/2 - 1)
106-
// fn recombine(&self) -> (Vec<F>, Vec<F>) {}
107-
10898
fn extend_impl(&self, evals: &[F], moiety: Moiety) -> Vec<F> {
10999
let n = evals.len();
110100
if n == 1 {
@@ -195,6 +185,7 @@ impl<F: Field> FFTree<F> {
195185
.collect()
196186
}
197187

188+
/// Converts from coefficient to evaluation representation of a polynomial
198189
pub fn enter(&self, coeffs: &[F]) -> Vec<F> {
199190
let tree = self.subtree_with_size(coeffs.len());
200191
tree.enter_impl(coeffs)
@@ -216,7 +207,7 @@ impl<F: Field> FFTree<F> {
216207
return subtree.degree_impl(&e0);
217208
}
218209

219-
// compute <(π-g)/Z_0 ≀ S1>
210+
// compute `<(π-g)/Z_0 ≀ S1>`
220211
// isolate the evaluations of the coefficients on the RHS
221212
let t1: Vec<F> = zip(zip(e1, g1), &self.z0_inv_s1)
222213
.map(|((e1, g1), z0_inv)| (e1 - g1) * z0_inv)
@@ -225,7 +216,7 @@ impl<F: Field> FFTree<F> {
225216
n / 2 + subtree.degree_impl(&t0)
226217
}
227218

228-
/// Evaluates the degree of an evaluation table in O(n log n)
219+
/// Evaluates the degree of an evaluation table in `O(n log n)`
229220
pub fn degree(&self, evals: &[F]) -> usize {
230221
let tree = self.subtree_with_size(evals.len());
231222
tree.degree_impl(evals)
@@ -257,6 +248,7 @@ impl<F: Field> FFTree<F> {
257248
a
258249
}
259250

251+
/// Converts from evaluation to coefficient representation of a polynomial
260252
pub fn exit(&self, evals: &[F]) -> Vec<F> {
261253
let tree = self.subtree_with_size(evals.len());
262254
tree.exit_impl(evals)
@@ -282,7 +274,7 @@ impl<F: Field> FFTree<F> {
282274
Moiety::S1 => &self.z1_inv_s0,
283275
};
284276

285-
// compute <(π - a*g)/Z ≀ S'>
277+
// compute `<(π - a*g)/Z ≀ S'>`
286278
let h1: Vec<F> = zip(zip(e1, g1), zip(a1, z_inv))
287279
.map(|((e1, g1), (a1, z0_inv))| (e1 - g1 * a1) * z0_inv)
288280
.collect();
@@ -293,15 +285,15 @@ impl<F: Field> FFTree<F> {
293285

294286
/// Computes <P(X)*Z_0(x)^(-1) mod a ≀ S>
295287
/// Z_0 is the vanishing polynomial of S_0
296-
/// `a` must be a polynomial of degree at most n/2 having no zeroes in S_0
288+
/// `a` must be a polynomial of max degree `n/2` having no zeroes in `S_0`
297289
pub fn redc_z0(&self, evals: &[F], a: &[F]) -> Vec<F> {
298290
let tree = self.subtree_with_size(evals.len());
299291
tree.redc_impl(evals, a, Moiety::S0)
300292
}
301293

302-
/// Computes <P(X)*Z_1(x)^(-1) mod A ≀ S>
303-
/// Z_1 is the vanishing polynomial of S_1
304-
/// `A` must be a polynomial of degree at most n/2 having no zeroes in S_1
294+
/// Computes `<P(X)*Z_1(x)^(-1) mod A ≀ S>`
295+
/// `Z_1` is the vanishing polynomial of `S_1`
296+
/// `A` must be a polynomial of max degree `n/2` having no zeroes in `S_1`
305297
pub fn redc_z1(&self, evals: &[F], a: &[F]) -> Vec<F> {
306298
let tree = self.subtree_with_size(evals.len());
307299
tree.redc_impl(evals, a, Moiety::S1)
@@ -314,8 +306,8 @@ impl<F: Field> FFTree<F> {
314306
}
315307

316308
/// Computes MOD algorithm
317-
/// `a` must be a polynomial of degree at most n/2 having no zeroes in S_0
318-
/// `c` must be the evaluation table <Z_0^2 mod a ≀ S>
309+
/// `a` must be a polynomial of max degree `n/2` having no zeroes in `S_0`
310+
/// `c` must be the evaluation table `<Z_0^2 mod a ≀ S>`
319311
pub fn modular_reduce(&self, evals: &[F], a: &[F], c: &[F]) -> Vec<F> {
320312
let tree = self.subtree_with_size(evals.len());
321313
tree.modular_reduce_impl(evals, a, c)
@@ -340,8 +332,8 @@ impl<F: Field> FFTree<F> {
340332
.collect()
341333
}
342334

343-
/// Returns an evaluation of the vanishing polynomial Z(x) = ∏ (x - a_i)
344-
/// Runtime O(n log^2 n). `vanishi_domain = [a_0, a_1, ..., a_(n - 1)]`
335+
/// Returns an evaluation of the vanishing polynomial `Z(x) = ∏ (x - a_i)`
336+
/// Runtime `O(n log^2 n)`. `vanishi_domain = [a_0, a_1, ..., a_(n - 1)]`
345337
/// Section 7.1 https://arxiv.org/pdf/2107.08473.pdf
346338
pub fn vanish(&self, vanish_domain: &[F]) -> Vec<F> {
347339
let tree = self.subtree_with_size(vanish_domain.len() * 2);

0 commit comments

Comments
 (0)