-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add speed test for iterative vs. recursive FFT
- Loading branch information
Showing
5 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use prio::benchmarked::{benchmarked_iterative_fft, benchmarked_recursive_fft}; | ||
use prio::finite_field::{Field, FieldElement}; | ||
|
||
pub fn fft(c: &mut Criterion) { | ||
let test_sizes = [16, 256, 1024, 4096]; | ||
for size in test_sizes.iter() { | ||
let mut rng = rand::thread_rng(); | ||
let mut inp = vec![Field::zero(); *size]; | ||
let mut outp = vec![Field::zero(); *size]; | ||
for i in 0..*size { | ||
inp[i] = Field::rand(&mut rng); | ||
} | ||
|
||
c.bench_function(&format!("iterative/{}", *size), |b| { | ||
b.iter(|| { | ||
benchmarked_iterative_fft(&mut outp, &inp); | ||
}) | ||
}); | ||
|
||
c.bench_function(&format!("recursive/{}", *size), |b| { | ||
b.iter(|| { | ||
benchmarked_recursive_fft(&mut outp, &inp); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, fft); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
//! This packages provides wrappers around internal components of this crate that we wnat to | ||
//! benchmark, but which we don't want to expose in the public API. | ||
use crate::fft::discrete_fourier_transform; | ||
use crate::finite_field::{Field, FieldElement}; | ||
use crate::polynomial::{poly_fft, PolyAuxMemory}; | ||
|
||
/// Sets `outp` to the Discrete Fourier Transform (DFT) using an iterative FFT algorithm. | ||
pub fn benchmarked_iterative_fft<F: FieldElement>(outp: &mut [F], inp: &[F]) { | ||
discrete_fourier_transform(outp, inp).expect("encountered unexpected error"); | ||
} | ||
|
||
/// Sets `outp` to the Discrete Fourier Transform (DFT) using a recursive FFT algorithm. | ||
pub fn benchmarked_recursive_fft(outp: &mut [Field], inp: &[Field]) { | ||
let mut mem = PolyAuxMemory::new(inp.len() / 2); | ||
poly_fft( | ||
outp, | ||
inp, | ||
&mem.roots_2n, | ||
inp.len(), | ||
false, | ||
&mut mem.fft_memory, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters