Skip to content

Commit

Permalink
Add throughput benchmark for realfft
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Jun 15, 2024
1 parent 62cc47a commit 6b4b03c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ multiversion = "0.7"
utilities = { path = "utilities" }
fftw = "0.8.0"
criterion = "0.5.1"
realfft = "3.3.0"

[[bench]]
name = "bench"
Expand Down
22 changes: 20 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use phastft::{fft::r2c_fft_f64, fft_64, planner::Direction};
use realfft::num_complex::Complex;
use realfft::RealFftPlanner;
use utilities::gen_random_signal;

use phastft::{fft::r2c_fft_f64, fft_64, planner::Direction};

fn criterion_benchmark(c: &mut Criterion) {
let sizes = vec![1 << 10, 1 << 12, 1 << 14, 1 << 16, 1 << 18, 1 << 20];
// let sizes = vec![1 << 10, 1 << 12, 1 << 14, 1 << 16, 1 << 18, 1 << 20];
let sizes = vec![1 << 18, 1 << 20];

let mut group = c.benchmark_group("r2c_versus_c2c");
for &size in &sizes {
Expand Down Expand Up @@ -39,6 +43,20 @@ fn criterion_benchmark(c: &mut Criterion) {
);
});
});

group.bench_with_input(BenchmarkId::new("real_fft", size), &size, |b, &size| {
let mut s_re = vec![0.0; size];
let mut s_im = vec![0.0; size];
gen_random_signal(&mut s_re, &mut s_im);
let mut output = vec![Complex::default(); s_re.len() / 2 + 1];

b.iter(|| {
let mut planner = RealFftPlanner::<f64>::new();
let fft = planner.plan_fft_forward(s_re.len());
fft.process(&mut s_re, &mut output)
.expect("fft.process() failed!");
});
});
}
group.finish();
}
Expand Down

0 comments on commit 6b4b03c

Please sign in to comment.