-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfft_rev.rs
63 lines (53 loc) · 1.63 KB
/
fft_rev.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Testing O(n) FFT(v.rev()) algorithm vs O(n*log n) naive impl
//! `cargo bench --bench fft_rev`
#[macro_use]
extern crate criterion;
use ark_bn254::Fr;
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
use ark_std::{
rand::{rngs::StdRng, SeedableRng},
UniformRand,
};
use itertools::Itertools;
use criterion::Criterion;
use vrs::multi_evals::fft_rev;
/// a CryptoRng
pub fn test_rng() -> StdRng {
// arbitrary seed
let seed = [
1, 0, 0, 0, 23, 0, 0, 0, 200, 1, 0, 0, 210, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0,
];
StdRng::from_seed(seed)
}
fn fast_fft_rev(c: &mut Criterion) {
let rng = &mut test_rng();
let degrees = [2usize.pow(12), 2usize.pow(13)];
let domain_sizes = [2usize.pow(14), 2usize.pow(15), 2usize.pow(16)];
for (deg, domain_size) in degrees
.into_iter()
.cartesian_product(domain_sizes.into_iter())
{
let mut group =
c.benchmark_group(format!("fft_rev::deg={},domain_size={}", deg, domain_size));
group.sample_size(10);
let domain = Radix2EvaluationDomain::<Fr>::new(domain_size).unwrap();
let mut v = vec![];
for _ in 0..deg + 1 {
v.push(Fr::rand(rng));
}
let fft_result = domain.fft(&v);
group.bench_function("fast", |b| {
b.iter(|| fft_rev(&domain, deg + 1, &fft_result))
});
group.bench_function("naive", |b| {
b.iter(|| {
v.reverse();
domain.fft(&v)
})
});
group.finish();
}
}
criterion_group!(benches, fast_fft_rev);
criterion_main!(benches);