|
1 | 1 | use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; |
2 | | -use ferrous_waves::analysis::spectral::{FftProcessor, WindowFunction}; |
| 2 | +use ferrous_waves::analysis::spectral::{ |
| 3 | + FftProcessor, SimdFft, SimdWindowFunctions, WindowFunction, |
| 4 | +}; |
| 5 | +use num_complex::Complex32; |
3 | 6 |
|
4 | 7 | fn benchmark_fft_sizes(c: &mut Criterion) { |
5 | 8 | let sizes = vec![256, 512, 1024, 2048, 4096, 8192]; |
@@ -62,10 +65,74 @@ fn benchmark_fft_operations(c: &mut Criterion) { |
62 | 65 | group.finish(); |
63 | 66 | } |
64 | 67 |
|
| 68 | +fn benchmark_simd_fft(c: &mut Criterion) { |
| 69 | + let mut group = c.benchmark_group("simd_fft"); |
| 70 | + let sizes = vec![256, 512, 1024, 2048, 4096, 8192]; |
| 71 | + |
| 72 | + for size in sizes { |
| 73 | + let mut simd_fft = SimdFft::new(size); |
| 74 | + let input: Vec<f32> = (0..size).map(|i| (i as f32 * 0.01).sin()).collect(); |
| 75 | + |
| 76 | + group.bench_with_input(BenchmarkId::new("process", size), &size, |b, _| { |
| 77 | + b.iter(|| simd_fft.process(black_box(&input))); |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + group.finish(); |
| 82 | +} |
| 83 | + |
| 84 | +fn benchmark_simd_operations(c: &mut Criterion) { |
| 85 | + let mut group = c.benchmark_group("simd_operations"); |
| 86 | + let size = 2048; |
| 87 | + |
| 88 | + let spectrum: Vec<Complex32> = (0..size) |
| 89 | + .map(|i| Complex32::new((i as f32 * 0.01).sin(), (i as f32 * 0.02).cos())) |
| 90 | + .collect(); |
| 91 | + |
| 92 | + group.bench_function("magnitude_spectrum_simd", |b| { |
| 93 | + b.iter(|| SimdFft::magnitude_spectrum_simd(black_box(&spectrum))); |
| 94 | + }); |
| 95 | + |
| 96 | + group.bench_function("power_spectrum_simd", |b| { |
| 97 | + b.iter(|| SimdFft::power_spectrum_simd(black_box(&spectrum))); |
| 98 | + }); |
| 99 | + |
| 100 | + let mut samples = vec![1.0; size]; |
| 101 | + let window = SimdWindowFunctions::hann_simd(size); |
| 102 | + |
| 103 | + group.bench_function("apply_window_simd", |b| { |
| 104 | + b.iter(|| SimdFft::apply_window_simd(black_box(&mut samples), black_box(&window))); |
| 105 | + }); |
| 106 | + |
| 107 | + group.finish(); |
| 108 | +} |
| 109 | + |
| 110 | +fn benchmark_simd_windows(c: &mut Criterion) { |
| 111 | + let mut group = c.benchmark_group("simd_windows"); |
| 112 | + let size = 2048; |
| 113 | + |
| 114 | + group.bench_function("hann_simd", |b| { |
| 115 | + b.iter(|| SimdWindowFunctions::hann_simd(black_box(size))); |
| 116 | + }); |
| 117 | + |
| 118 | + group.bench_function("hamming_simd", |b| { |
| 119 | + b.iter(|| SimdWindowFunctions::hamming_simd(black_box(size))); |
| 120 | + }); |
| 121 | + |
| 122 | + group.bench_function("blackman_simd", |b| { |
| 123 | + b.iter(|| SimdWindowFunctions::blackman_simd(black_box(size))); |
| 124 | + }); |
| 125 | + |
| 126 | + group.finish(); |
| 127 | +} |
| 128 | + |
65 | 129 | criterion_group!( |
66 | 130 | benches, |
67 | 131 | benchmark_fft_sizes, |
68 | 132 | benchmark_window_functions, |
69 | | - benchmark_fft_operations |
| 133 | + benchmark_fft_operations, |
| 134 | + benchmark_simd_fft, |
| 135 | + benchmark_simd_operations, |
| 136 | + benchmark_simd_windows |
70 | 137 | ); |
71 | 138 | criterion_main!(benches); |
0 commit comments