-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Planner should be re-usable so it can be re-used for FFT's of the same size - Add regression tests to make sure `fft_64`/`fft_32` gives the same results as `fft_64_with_opts_and_plan`/`fft_32_with_opts_and_plan`
- Loading branch information
Showing
6 changed files
with
272 additions
and
43 deletions.
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,119 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use num_traits::Float; | ||
use phastft::{ | ||
fft_32_with_opts_and_plan, fft_64_with_opts_and_plan, | ||
options::Options, | ||
planner::{Direction, Planner32, Planner64}, | ||
}; | ||
use rand::{ | ||
distributions::{Distribution, Standard}, | ||
thread_rng, Rng, | ||
}; | ||
|
||
const LENGTHS: &[usize] = &[ | ||
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, | ||
]; | ||
|
||
fn generate_numbers<T: Float>(n: usize) -> (Vec<T>, Vec<T>) | ||
where | ||
Standard: Distribution<T>, | ||
{ | ||
let mut rng = thread_rng(); | ||
|
||
let samples: Vec<T> = (&mut rng).sample_iter(Standard).take(2 * n).collect(); | ||
|
||
let mut reals = vec![T::zero(); n]; | ||
let mut imags = vec![T::zero(); n]; | ||
|
||
for ((z_re, z_im), rand_chunk) in reals | ||
.iter_mut() | ||
.zip(imags.iter_mut()) | ||
.zip(samples.chunks_exact(2)) | ||
{ | ||
*z_re = rand_chunk[0]; | ||
*z_im = rand_chunk[1]; | ||
} | ||
|
||
(reals, imags) | ||
} | ||
|
||
fn benchmark_forward_f32(c: &mut Criterion) { | ||
let options = Options::default(); | ||
|
||
for n in LENGTHS.iter() { | ||
let len = 1 << n; | ||
let id = format!("FFT Forward f32 {} elements", len); | ||
c.bench_function(&id, |b| { | ||
let (mut reals, mut imags) = generate_numbers(len); | ||
let planner = Planner32::new(len, Direction::Forward); | ||
b.iter(|| { | ||
black_box(fft_32_with_opts_and_plan( | ||
&mut reals, &mut imags, &options, &planner, | ||
)); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
fn benchmark_inverse_f32(c: &mut Criterion) { | ||
let options = Options::default(); | ||
|
||
for n in LENGTHS.iter() { | ||
let len = 1 << n; | ||
let id = format!("FFT Inverse f32 {} elements", len); | ||
c.bench_function(&id, |b| { | ||
let (mut reals, mut imags) = generate_numbers(len); | ||
let planner = Planner32::new(len, Direction::Reverse); | ||
b.iter(|| { | ||
black_box(fft_32_with_opts_and_plan( | ||
&mut reals, &mut imags, &options, &planner, | ||
)); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
fn benchmark_forward_f64(c: &mut Criterion) { | ||
let options = Options::default(); | ||
|
||
for n in LENGTHS.iter() { | ||
let len = 1 << n; | ||
let id = format!("FFT Forward f64 {} elements", len); | ||
c.bench_function(&id, |b| { | ||
let (mut reals, mut imags) = generate_numbers(len); | ||
let planner = Planner64::new(len, Direction::Forward); | ||
b.iter(|| { | ||
black_box(fft_64_with_opts_and_plan( | ||
&mut reals, &mut imags, &options, &planner, | ||
)); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
fn benchmark_inverse_f64(c: &mut Criterion) { | ||
let options = Options::default(); | ||
|
||
for n in LENGTHS.iter() { | ||
let len = 1 << n; | ||
let id = format!("FFT Inverse f64 {} elements", len); | ||
c.bench_function(&id, |b| { | ||
let (mut reals, mut imags) = generate_numbers(len); | ||
let planner = Planner64::new(len, Direction::Reverse); | ||
b.iter(|| { | ||
black_box(fft_64_with_opts_and_plan( | ||
&mut reals, &mut imags, &options, &planner, | ||
)); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
benchmark_forward_f32, | ||
benchmark_inverse_f32, | ||
benchmark_forward_f64, | ||
benchmark_inverse_f64 | ||
); | ||
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
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
Oops, something went wrong.