Debian Codegraph @

.cargo/vendor/rustfft/benches/bench_rustfft.rs

raw
1 #![allow(bare_trait_objects)]
2 #![allow(non_snake_case)]
3 #![feature(test)]
4 extern crate test;
5 extern crate rustfft;
6
7 use std::sync::Arc;
8 use test::Bencher;
9 use rustfft::{Direction, FftNum, Fft, FftDirection, Length};
10 use rustfft::num_complex::Complex;
11 use rustfft::num_traits::Zero;
12 use rustfft::algorithm::*;
13 use rustfft::algorithm::butterflies::*;
14
15 struct Noop {
16 len: usize,
17 direction: FftDirection,
18 }
19 impl<T: FftNum> Fft<T> for Noop {
20 fn process_with_scratch(&self, _buffer: &mut [Complex<T>], _scratch: &mut [Complex<T>]) {}
21 fn process_outofplace_with_scratch(&self, _input: &mut [Complex<T>], _output: &mut [Complex<T>], _scratch: &mut [Complex<T>]) {}
22 fn get_inplace_scratch_len(&self) -> usize { self.len }
23 fn get_outofplace_scratch_len(&self) -> usize { 0 }
24 }
25 impl Length for Noop {
26 fn len(&self) -> usize { self.len }
27 }
28 impl Direction for Noop {
29 fn fft_direction(&self) -> FftDirection { self.direction }
30 }
31
32 /// Times just the FFT execution (not allocation and pre-calculation)
33 /// for a given length
34 fn bench_planned_f32(b: &mut Bencher, len: usize) {
35
36 let mut planner = rustfft::FftPlanner::new();
37 let fft: Arc<dyn Fft<f32>> = planner.plan_fft_forward(len);
38 assert_eq!(fft.len(), len);
39
40 let mut buffer = vec![Complex::zero(); len];
41 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
42 b.iter(|| {
43 fft.process_with_scratch(&mut buffer, &mut scratch);
44 });
45 }
46
47
48 // Powers of 4
49 #[bench] fn planned32_p2_00000064(b: &mut Bencher) { bench_planned_f32(b, 64); }
50 #[bench] fn planned32_p2_00000128(b: &mut Bencher) { bench_planned_f32(b, 128); }
51 #[bench] fn planned32_p2_00000256(b: &mut Bencher) { bench_planned_f32(b, 256); }
52 #[bench] fn planned32_p2_00000512(b: &mut Bencher) { bench_planned_f32(b, 512); }
53 #[bench] fn planned32_p2_00001024(b: &mut Bencher) { bench_planned_f32(b, 1024); }
54 #[bench] fn planned32_p2_00002048(b: &mut Bencher) { bench_planned_f32(b, 2048); }
55 #[bench] fn planned32_p2_00004096(b: &mut Bencher) { bench_planned_f32(b, 4096); }
56 #[bench] fn planned32_p2_00016384(b: &mut Bencher) { bench_planned_f32(b, 16384); }
57 #[bench] fn planned32_p2_00065536(b: &mut Bencher) { bench_planned_f32(b, 65536); }
58 #[bench] fn planned32_p2_01048576(b: &mut Bencher) { bench_planned_f32(b, 1048576); }
59 #[bench] fn planned32_p2_16777216(b: &mut Bencher) { bench_planned_f32(b, 16777216); }
60
61
62 // Powers of 5
63 #[bench] fn planned32_p5_00125(b: &mut Bencher) { bench_planned_f32(b, 125); }
64 #[bench] fn planned32_p5_00625(b: &mut Bencher) { bench_planned_f32(b, 625); }
65 #[bench] fn planned32_p5_03125(b: &mut Bencher) { bench_planned_f32(b, 3125); }
66 #[bench] fn planned32_p5_15625(b: &mut Bencher) { bench_planned_f32(b, 15625); }
67
68 // Powers of 7
69 #[bench] fn planned32_p7_00343(b: &mut Bencher) { bench_planned_f32(b, 343); }
70 #[bench] fn planned32_p7_02401(b: &mut Bencher) { bench_planned_f32(b, 2401); }
71 #[bench] fn planned32_p7_16807(b: &mut Bencher) { bench_planned_f32(b, 16807); }
72
73 // Prime lengths
74 // Prime lengths
75 #[bench] fn planned32_prime_0005(b: &mut Bencher) { bench_planned_f32(b, 5); }
76 #[bench] fn planned32_prime_0017(b: &mut Bencher) { bench_planned_f32(b, 17); }
77 #[bench] fn planned32_prime_0149(b: &mut Bencher) { bench_planned_f32(b, 149); }
78 #[bench] fn planned32_prime_0151(b: &mut Bencher) { bench_planned_f32(b, 151); }
79 #[bench] fn planned32_prime_0251(b: &mut Bencher) { bench_planned_f32(b, 251); }
80 #[bench] fn planned32_prime_0257(b: &mut Bencher) { bench_planned_f32(b, 257); }
81 #[bench] fn planned32_prime_1009(b: &mut Bencher) { bench_planned_f32(b, 1009); }
82 #[bench] fn planned32_prime_1201(b: &mut Bencher) { bench_planned_f32(b, 1201); }
83 #[bench] fn planned32_prime_2017(b: &mut Bencher) { bench_planned_f32(b, 2017); }
84 #[bench] fn planned32_prime_2879(b: &mut Bencher) { bench_planned_f32(b, 2879); }
85 #[bench] fn planned32_prime_32767(b: &mut Bencher) { bench_planned_f32(b, 32767); }
86 #[bench] fn planned32_prime_65521(b: &mut Bencher) { bench_planned_f32(b, 65521); }
87 #[bench] fn planned32_prime_65537(b: &mut Bencher) { bench_planned_f32(b, 65537); }
88 #[bench] fn planned32_prime_746483(b: &mut Bencher) { bench_planned_f32(b,746483); }
89 #[bench] fn planned32_prime_746497(b: &mut Bencher) { bench_planned_f32(b,746497); }
90
91 //primes raised to a power
92 #[bench] fn planned32_primepower_044521(b: &mut Bencher) { bench_planned_f32(b, 44521); } // 211^2
93 #[bench] fn planned32_primepower_160801(b: &mut Bencher) { bench_planned_f32(b, 160801); } // 401^2
94
95 // numbers times powers of two
96 #[bench] fn planned32_composite_024576(b: &mut Bencher) { bench_planned_f32(b, 24576); }
97 #[bench] fn planned32_composite_020736(b: &mut Bencher) { bench_planned_f32(b, 20736); }
98
99 // power of 2 times large prime
100 #[bench] fn planned32_composite_032192(b: &mut Bencher) { bench_planned_f32(b, 32192); }
101 #[bench] fn planned32_composite_024028(b: &mut Bencher) { bench_planned_f32(b, 24028); }
102
103 // small mixed composites times a large prime
104 #[bench] fn planned32_composite_005472(b: &mut Bencher) { bench_planned_f32(b, 5472); }
105 #[bench] fn planned32_composite_030270(b: &mut Bencher) { bench_planned_f32(b, 30270); }
106
107 // small mixed composites
108 #[bench] fn planned32_composite_000018(b: &mut Bencher) { bench_planned_f32(b, 00018); }
109 #[bench] fn planned32_composite_000360(b: &mut Bencher) { bench_planned_f32(b, 00360); }
110 #[bench] fn planned32_composite_001200(b: &mut Bencher) { bench_planned_f32(b, 01200); }
111 #[bench] fn planned32_composite_044100(b: &mut Bencher) { bench_planned_f32(b, 44100); }
112 #[bench] fn planned32_composite_048000(b: &mut Bencher) { bench_planned_f32(b, 48000); }
113 #[bench] fn planned32_composite_046656(b: &mut Bencher) { bench_planned_f32(b, 46656); }
114 #[bench] fn planned32_composite_100000(b: &mut Bencher) { bench_planned_f32(b, 100000); }
115
116 /// Times just the FFT execution (not allocation and pre-calculation)
117 /// for a given length
118 fn bench_planned_f64(b: &mut Bencher, len: usize) {
119
120 let mut planner = rustfft::FftPlanner::new();
121 let fft: Arc<dyn Fft<f64>> = planner.plan_fft_forward(len);
122
123 let mut buffer = vec![Complex::zero(); len];
124 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
125 b.iter(|| { fft.process_with_scratch(&mut buffer, &mut scratch); });
126 }
127
128 #[bench] fn planned64_p2_00000064(b: &mut Bencher) { bench_planned_f64(b, 64); }
129 #[bench] fn planned64_p2_00000128(b: &mut Bencher) { bench_planned_f64(b, 128); }
130 #[bench] fn planned64_p2_00000256(b: &mut Bencher) { bench_planned_f64(b, 256); }
131 #[bench] fn planned64_p2_00000512(b: &mut Bencher) { bench_planned_f64(b, 512); }
132 #[bench] fn planned64_p2_00001024(b: &mut Bencher) { bench_planned_f64(b, 1024); }
133 #[bench] fn planned64_p2_00002048(b: &mut Bencher) { bench_planned_f64(b, 2048); }
134 #[bench] fn planned64_p2_00004096(b: &mut Bencher) { bench_planned_f64(b, 4096); }
135 #[bench] fn planned64_p2_00016384(b: &mut Bencher) { bench_planned_f64(b, 16384); }
136 #[bench] fn planned64_p2_00065536(b: &mut Bencher) { bench_planned_f64(b, 65536); }
137 #[bench] fn planned64_p2_01048576(b: &mut Bencher) { bench_planned_f64(b, 1048576); }
138 //#[bench] fn planned64_p2_16777216(b: &mut Bencher) { bench_planned_f64(b, 16777216); }
139
140 // Powers of 5
141 #[bench] fn planned64_p5_00125(b: &mut Bencher) { bench_planned_f64(b, 125); }
142 #[bench] fn planned64_p5_00625(b: &mut Bencher) { bench_planned_f64(b, 625); }
143 #[bench] fn planned64_p5_03125(b: &mut Bencher) { bench_planned_f64(b, 3125); }
144 #[bench] fn planned64_p5_15625(b: &mut Bencher) { bench_planned_f64(b, 15625); }
145
146 #[bench] fn planned64_p7_00343(b: &mut Bencher) { bench_planned_f64(b, 343); }
147 #[bench] fn planned64_p7_02401(b: &mut Bencher) { bench_planned_f64(b, 2401); }
148 #[bench] fn planned64_p7_16807(b: &mut Bencher) { bench_planned_f64(b, 16807); }
149
150 // Prime lengths
151 #[bench] fn planned64_prime_0005(b: &mut Bencher) { bench_planned_f64(b, 5); }
152 #[bench] fn planned64_prime_0017(b: &mut Bencher) { bench_planned_f64(b, 17); }
153 #[bench] fn planned64_prime_0149(b: &mut Bencher) { bench_planned_f64(b, 149); }
154 #[bench] fn planned64_prime_0151(b: &mut Bencher) { bench_planned_f64(b, 151); }
155 #[bench] fn planned64_prime_0251(b: &mut Bencher) { bench_planned_f64(b, 251); }
156 #[bench] fn planned64_prime_0257(b: &mut Bencher) { bench_planned_f64(b, 257); }
157 #[bench] fn planned64_prime_1009(b: &mut Bencher) { bench_planned_f64(b, 1009); }
158 #[bench] fn planned64_prime_2017(b: &mut Bencher) { bench_planned_f64(b, 2017); }
159 #[bench] fn planned64_prime_2879(b: &mut Bencher) { bench_planned_f64(b, 2879); }
160 #[bench] fn planned64_prime_32767(b: &mut Bencher) { bench_planned_f64(b, 32767); }
161 #[bench] fn planned64_prime_65521(b: &mut Bencher) { bench_planned_f64(b, 65521); }
162 #[bench] fn planned64_prime_65537(b: &mut Bencher) { bench_planned_f64(b, 65537); }
163 #[bench] fn planned64_prime_746483(b: &mut Bencher) { bench_planned_f64(b,746483); }
164 #[bench] fn planned64_prime_746497(b: &mut Bencher) { bench_planned_f64(b,746497); }
165
166 //primes raised to a power
167 #[bench] fn planned64_primepower_044521(b: &mut Bencher) { bench_planned_f64(b, 44521); } // 211^2
168 #[bench] fn planned64_primepower_160801(b: &mut Bencher) { bench_planned_f64(b, 160801); } // 401^2
169
170 // numbers times powers of two
171 #[bench] fn planned64_composite_024576(b: &mut Bencher) { bench_planned_f64(b, 24576); }
172 #[bench] fn planned64_composite_020736(b: &mut Bencher) { bench_planned_f64(b, 20736); }
173
174 // power of 2 times large prime
175 #[bench] fn planned64_composite_032192(b: &mut Bencher) { bench_planned_f64(b, 32192); }
176 #[bench] fn planned64_composite_024028(b: &mut Bencher) { bench_planned_f64(b, 24028); }
177
178 // small mixed composites times a large prime
179 #[bench] fn planned64_composite_030270(b: &mut Bencher) { bench_planned_f64(b, 30270); }
180
181 // small mixed composites
182 #[bench] fn planned64_composite_000018(b: &mut Bencher) { bench_planned_f64(b, 00018); }
183 #[bench] fn planned64_composite_000360(b: &mut Bencher) { bench_planned_f64(b, 00360); }
184 #[bench] fn planned64_composite_044100(b: &mut Bencher) { bench_planned_f64(b, 44100); }
185 #[bench] fn planned64_composite_048000(b: &mut Bencher) { bench_planned_f64(b, 48000); }
186 #[bench] fn planned64_composite_046656(b: &mut Bencher) { bench_planned_f64(b, 46656); }
187 #[bench] fn planned64_composite_100000(b: &mut Bencher) { bench_planned_f64(b, 100000); }
188
189 /// Times just the FFT execution (not allocation and pre-calculation)
190 /// for a given length, specific to the Good-Thomas algorithm
191 fn bench_good_thomas(b: &mut Bencher, width: usize, height: usize) {
192
193 let mut planner = rustfft::FftPlanner::new();
194 let width_fft = planner.plan_fft_forward(width);
195 let height_fft = planner.plan_fft_forward(height);
196
197 let fft : Arc<Fft<f32>> = Arc::new(GoodThomasAlgorithm::new(width_fft, height_fft));
198
199 let mut buffer = vec![Complex::zero(); width * height];
200 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
201 b.iter(|| {fft.process_with_scratch(&mut buffer, &mut scratch);} );
202 }
203
204 #[bench] fn good_thomas_0002_3(b: &mut Bencher) { bench_good_thomas(b, 2, 3); }
205 #[bench] fn good_thomas_0003_4(b: &mut Bencher) { bench_good_thomas(b, 3, 4); }
206 #[bench] fn good_thomas_0004_5(b: &mut Bencher) { bench_good_thomas(b, 4, 5); }
207 #[bench] fn good_thomas_0007_32(b: &mut Bencher) { bench_good_thomas(b, 7, 32); }
208 #[bench] fn good_thomas_0032_27(b: &mut Bencher) { bench_good_thomas(b, 32, 27); }
209 #[bench] fn good_thomas_0256_243(b: &mut Bencher) { bench_good_thomas(b, 256, 243); }
210 #[bench] fn good_thomas_2048_3(b: &mut Bencher) { bench_good_thomas(b, 2048, 3); }
211 #[bench] fn good_thomas_2048_2187(b: &mut Bencher) { bench_good_thomas(b, 2048, 2187); }
212
213 /// Times just the FFT setup (not execution)
214 /// for a given length, specific to the Good-Thomas algorithm
215 fn bench_good_thomas_setup(b: &mut Bencher, width: usize, height: usize) {
216
217 let mut planner = rustfft::FftPlanner::new();
218 let width_fft = planner.plan_fft_forward(width);
219 let height_fft = planner.plan_fft_forward(height);
220
221 b.iter(|| {
222 let fft : Arc<Fft<f32>> = Arc::new(GoodThomasAlgorithm::new(Arc::clone(&width_fft), Arc::clone(&height_fft)));
223 test::black_box(fft);
224 });
225 }
226
227 #[bench] fn good_thomas_setup_0002_3(b: &mut Bencher) { bench_good_thomas_setup(b, 2, 3); }
228 #[bench] fn good_thomas_setup_0003_4(b: &mut Bencher) { bench_good_thomas_setup(b, 3, 4); }
229 #[bench] fn good_thomas_setup_0004_5(b: &mut Bencher) { bench_good_thomas_setup(b, 4, 5); }
230 #[bench] fn good_thomas_setup_0007_32(b: &mut Bencher) { bench_good_thomas_setup(b, 7, 32); }
231 #[bench] fn good_thomas_setup_0032_27(b: &mut Bencher) { bench_good_thomas_setup(b, 32, 27); }
232 #[bench] fn good_thomas_setup_0256_243(b: &mut Bencher) { bench_good_thomas_setup(b, 256, 243); }
233 #[bench] fn good_thomas_setup_2048_3(b: &mut Bencher) { bench_good_thomas_setup(b, 2048, 3); }
234 #[bench] fn good_thomas_setup_2048_2187(b: &mut Bencher) { bench_good_thomas_setup(b, 2048, 2187); }
235
236 /// Times just the FFT setup (not execution)
237 /// for a given length, specific to MixedRadix
238 fn bench_mixed_radix_setup(b: &mut Bencher, width: usize, height: usize) {
239
240 let mut planner = rustfft::FftPlanner::new();
241 let width_fft = planner.plan_fft_forward(width);
242 let height_fft = planner.plan_fft_forward(height);
243
244 b.iter(|| {
245 let fft : Arc<Fft<f32>> = Arc::new(MixedRadix::new(Arc::clone(&width_fft), Arc::clone(&height_fft)));
246 test::black_box(fft);
247 });
248 }
249
250 #[bench] fn setup_mixed_radix_0002_3(b: &mut Bencher) { bench_mixed_radix_setup(b, 2, 3); }
251 #[bench] fn setup_mixed_radix_0003_4(b: &mut Bencher) { bench_mixed_radix_setup(b, 3, 4); }
252 #[bench] fn setup_mixed_radix_0004_5(b: &mut Bencher) { bench_mixed_radix_setup(b, 4, 5); }
253 #[bench] fn setup_mixed_radix_0007_32(b: &mut Bencher) { bench_mixed_radix_setup(b, 7, 32); }
254 #[bench] fn setup_mixed_radix_0032_27(b: &mut Bencher) { bench_mixed_radix_setup(b, 32, 27); }
255 #[bench] fn setup_mixed_radix_0256_243(b: &mut Bencher) { bench_mixed_radix_setup(b, 256, 243); }
256 #[bench] fn setup_mixed_radix_2048_3(b: &mut Bencher) { bench_mixed_radix_setup(b, 2048, 3); }
257 #[bench] fn setup_mixed_radix_2048_2187(b: &mut Bencher) { bench_mixed_radix_setup(b, 2048, 2187); }
258
259 /// Times just the FFT setup (not execution)
260 /// for a given length, specific to MixedRadix
261 fn bench_small_mixed_radix_setup(b: &mut Bencher, width: usize, height: usize) {
262
263 let mut planner = rustfft::FftPlanner::new();
264 let width_fft = planner.plan_fft_forward(width);
265 let height_fft = planner.plan_fft_forward(height);
266
267 b.iter(|| {
268 let fft : Arc<Fft<f32>> = Arc::new(MixedRadixSmall::new(Arc::clone(&width_fft), Arc::clone(&height_fft)));
269 test::black_box(fft);
270 });
271 }
272
273 #[bench] fn setup_small_mixed_radix_0002_3(b: &mut Bencher) { bench_small_mixed_radix_setup(b, 2, 3); }
274 #[bench] fn setup_small_mixed_radix_0003_4(b: &mut Bencher) { bench_small_mixed_radix_setup(b, 3, 4); }
275 #[bench] fn setup_small_mixed_radix_0004_5(b: &mut Bencher) { bench_small_mixed_radix_setup(b, 4, 5); }
276 #[bench] fn setup_small_mixed_radix_0007_32(b: &mut Bencher) { bench_small_mixed_radix_setup(b, 7, 32); }
277 #[bench] fn setup_small_mixed_radix_0032_27(b: &mut Bencher) { bench_small_mixed_radix_setup(b, 32, 27); }
278
279
280 /// Times just the FFT execution (not allocation and pre-calculation)
281 /// for a given length, specific to the Mixed-Radix algorithm
282 fn bench_mixed_radix(b: &mut Bencher, width: usize, height: usize) {
283
284 let mut planner = rustfft::FftPlanner::new();
285 let width_fft = planner.plan_fft_forward(width);
286 let height_fft = planner.plan_fft_forward(height);
287
288 let fft : Arc<Fft<_>> = Arc::new(MixedRadix::new(width_fft, height_fft));
289
290 let mut buffer = vec![Complex{re: 0_f32, im: 0_f32}; fft.len()];
291 let mut scratch = vec![Complex{re: 0_f32, im: 0_f32}; fft.get_inplace_scratch_len()];
292 b.iter(|| {fft.process_with_scratch(&mut buffer, &mut scratch);} );
293 }
294
295 #[bench] fn mixed_radix_0002_3(b: &mut Bencher) { bench_mixed_radix(b, 2, 3); }
296 #[bench] fn mixed_radix_0003_4(b: &mut Bencher) { bench_mixed_radix(b, 3, 4); }
297 #[bench] fn mixed_radix_0004_5(b: &mut Bencher) { bench_mixed_radix(b, 4, 5); }
298 #[bench] fn mixed_radix_0007_32(b: &mut Bencher) { bench_mixed_radix(b, 7, 32); }
299 #[bench] fn mixed_radix_0032_27(b: &mut Bencher) { bench_mixed_radix(b, 32, 27); }
300 #[bench] fn mixed_radix_0256_243(b: &mut Bencher) { bench_mixed_radix(b, 256, 243); }
301 #[bench] fn mixed_radix_2048_3(b: &mut Bencher) { bench_mixed_radix(b, 2048, 3); }
302 #[bench] fn mixed_radix_2048_2187(b: &mut Bencher) { bench_mixed_radix(b, 2048, 2187); }
303
304 fn plan_butterfly_fft(len: usize) -> Arc<Fft<f32>> {
305 match len {
306 2 => Arc::new(Butterfly2::new(FftDirection::Forward)),
307 3 => Arc::new(Butterfly3::new(FftDirection::Forward)),
308 4 => Arc::new(Butterfly4::new(FftDirection::Forward)),
309 5 => Arc::new(Butterfly5::new(FftDirection::Forward)),
310 6 => Arc::new(Butterfly6::new(FftDirection::Forward)),
311 7 => Arc::new(Butterfly7::new(FftDirection::Forward)),
312 8 => Arc::new(Butterfly8::new(FftDirection::Forward)),
313 16 => Arc::new(Butterfly16::new(FftDirection::Forward)),
314 32 => Arc::new(Butterfly32::new(FftDirection::Forward)),
315 _ => panic!("Invalid butterfly size: {}", len),
316 }
317 }
318
319 /// Times just the FFT execution (not allocation and pre-calculation)
320 /// for a given length, specific to the MixedRadixSmall algorithm
321 fn bench_mixed_radix_small(b: &mut Bencher, width: usize, height: usize) {
322
323 let width_fft = plan_butterfly_fft(width);
324 let height_fft = plan_butterfly_fft(height);
325
326 let fft : Arc<Fft<_>> = Arc::new(MixedRadixSmall::new(width_fft, height_fft));
327
328 let mut signal = vec![Complex{re: 0_f32, im: 0_f32}; width * height];
329 let mut spectrum = signal.clone();
330 b.iter(|| {fft.process_with_scratch(&mut signal, &mut spectrum);} );
331 }
332
333 #[bench] fn mixed_radix_small_0002_3(b: &mut Bencher) { bench_mixed_radix_small(b, 2, 3); }
334 #[bench] fn mixed_radix_small_0003_4(b: &mut Bencher) { bench_mixed_radix_small(b, 3, 4); }
335 #[bench] fn mixed_radix_small_0004_5(b: &mut Bencher) { bench_mixed_radix_small(b, 4, 5); }
336 #[bench] fn mixed_radix_small_0007_32(b: &mut Bencher) { bench_mixed_radix_small(b, 7, 32); }
337
338 /// Times just the FFT execution (not allocation and pre-calculation)
339 /// for a given length, specific to the Mixed-Radix Double Butterfly algorithm
340 fn bench_good_thomas_small(b: &mut Bencher, width: usize, height: usize) {
341
342 let width_fft = plan_butterfly_fft(width);
343 let height_fft = plan_butterfly_fft(height);
344
345 let fft : Arc<Fft<_>> = Arc::new(GoodThomasAlgorithmSmall::new(width_fft, height_fft));
346
347 let mut signal = vec![Complex{re: 0_f32, im: 0_f32}; width * height];
348 let mut spectrum = signal.clone();
349 b.iter(|| {fft.process_with_scratch(&mut signal, &mut spectrum);} );
350 }
351
352 #[bench] fn good_thomas_small_0002_3(b: &mut Bencher) { bench_good_thomas_small(b, 2, 3); }
353 #[bench] fn good_thomas_small_0003_4(b: &mut Bencher) { bench_good_thomas_small(b, 3, 4); }
354 #[bench] fn good_thomas_small_0004_5(b: &mut Bencher) { bench_good_thomas_small(b, 4, 5); }
355 #[bench] fn good_thomas_small_0007_32(b: &mut Bencher) { bench_good_thomas_small(b, 7, 32); }
356
357
358 /// Times just the FFT execution (not allocation and pre-calculation)
359 /// for a given length, specific to Rader's algorithm
360 fn bench_raders_scalar(b: &mut Bencher, len: usize) {
361
362 let mut planner = rustfft::FftPlanner::new();
363 let inner_fft = planner.plan_fft_forward(len - 1);
364
365 let fft : Arc<Fft<_>> = Arc::new(RadersAlgorithm::new(inner_fft));
366
367 let mut buffer = vec![Complex{re: 0_f32, im: 0_f32}; len];
368 let mut scratch = vec![Complex{re: 0_f32, im: 0_f32}; fft.get_inplace_scratch_len()];
369 b.iter(|| {fft.process_with_scratch(&mut buffer, &mut scratch);} );
370 }
371
372 #[bench] fn raders_fft_scalar_prime_0005(b: &mut Bencher) { bench_raders_scalar(b, 5); }
373 #[bench] fn raders_fft_scalar_prime_0017(b: &mut Bencher) { bench_raders_scalar(b, 17); }
374 #[bench] fn raders_fft_scalar_prime_0149(b: &mut Bencher) { bench_raders_scalar(b, 149); }
375 #[bench] fn raders_fft_scalar_prime_0151(b: &mut Bencher) { bench_raders_scalar(b, 151); }
376 #[bench] fn raders_fft_scalar_prime_0251(b: &mut Bencher) { bench_raders_scalar(b, 251); }
377 #[bench] fn raders_fft_scalar_prime_0257(b: &mut Bencher) { bench_raders_scalar(b, 257); }
378 #[bench] fn raders_fft_scalar_prime_1009(b: &mut Bencher) { bench_raders_scalar(b, 1009); }
379 #[bench] fn raders_fft_scalar_prime_2017(b: &mut Bencher) { bench_raders_scalar(b, 2017); }
380 #[bench] fn raders_fft_scalar_prime_12289(b: &mut Bencher) { bench_raders_scalar(b, 12289); }
381 #[bench] fn raders_fft_scalar_prime_18433(b: &mut Bencher) { bench_raders_scalar(b, 18433); }
382 #[bench] fn raders_fft_scalar_prime_65521(b: &mut Bencher) { bench_raders_scalar(b, 65521); }
383 #[bench] fn raders_fft_scalar_prime_65537(b: &mut Bencher) { bench_raders_scalar(b, 65537); }
384 #[bench] fn raders_fft_scalar_prime_746483(b: &mut Bencher) { bench_raders_scalar(b,746483); }
385 #[bench] fn raders_fft_scalar_prime_746497(b: &mut Bencher) { bench_raders_scalar(b,746497); }
386
387
388 /// Times just the FFT execution (not allocation and pre-calculation)
389 /// for a given length, specific to Bluestein's Algorithm
390 fn bench_bluesteins_scalar_prime(b: &mut Bencher, len: usize) {
391 let mut planner = rustfft::FftPlanner::new();
392 let inner_fft = planner.plan_fft_forward((len * 2 - 1).checked_next_power_of_two().unwrap());
393 let fft : Arc<Fft<f32>> = Arc::new(BluesteinsAlgorithm::new(len, inner_fft));
394
395 let mut buffer = vec![Zero::zero(); len];
396 let mut scratch = vec![Zero::zero(); fft.get_inplace_scratch_len()];
397 b.iter(|| { fft.process_with_scratch(&mut buffer, &mut scratch);} );
398 }
399
400 #[bench] fn bench_bluesteins_scalar_prime_0005(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 5); }
401 #[bench] fn bench_bluesteins_scalar_prime_0017(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 17); }
402 #[bench] fn bench_bluesteins_scalar_prime_0149(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 149); }
403 #[bench] fn bench_bluesteins_scalar_prime_0151(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 151); }
404 #[bench] fn bench_bluesteins_scalar_prime_0251(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 251); }
405 #[bench] fn bench_bluesteins_scalar_prime_0257(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 257); }
406 #[bench] fn bench_bluesteins_scalar_prime_1009(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 1009); }
407 #[bench] fn bench_bluesteins_scalar_prime_2017(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 2017); }
408 #[bench] fn bench_bluesteins_scalar_prime_32767(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 32767); }
409 #[bench] fn bench_bluesteins_scalar_prime_65521(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 65521); }
410 #[bench] fn bench_bluesteins_scalar_prime_65537(b: &mut Bencher) { bench_bluesteins_scalar_prime(b, 65537); }
411 #[bench] fn bench_bluesteins_scalar_prime_746483(b: &mut Bencher) { bench_bluesteins_scalar_prime(b,746483); }
412 #[bench] fn bench_bluesteins_scalar_prime_746497(b: &mut Bencher) { bench_bluesteins_scalar_prime(b,746497); }
413
414
415 /// Times just the FFT execution (not allocation and pre-calculation)
416 /// for a given length, specific to Rader's algorithm
417 fn bench_radix4(b: &mut Bencher, len: usize) {
418 assert!(len % 4 == 0);
419
420 let fft = Radix4::new(len, FftDirection::Forward);
421
422 let mut signal = vec![Complex{re: 0_f32, im: 0_f32}; len];
423 let mut spectrum = signal.clone();
424 b.iter(|| {fft.process_outofplace_with_scratch(&mut signal, &mut spectrum, &mut []);} );
425 }
426
427 #[bench] fn radix4_______64(b: &mut Bencher) { bench_radix4(b, 64); }
428 #[bench] fn radix4______256(b: &mut Bencher) { bench_radix4(b, 256); }
429 #[bench] fn radix4_____1024(b: &mut Bencher) { bench_radix4(b, 1024); }
430 #[bench] fn radix4____65536(b: &mut Bencher) { bench_radix4(b, 65536); }
431 #[bench] fn radix4__1048576(b: &mut Bencher) { bench_radix4(b, 1048576); }
432 //#[bench] fn radix4_16777216(b: &mut Bencher) { bench_radix4(b, 16777216); }
433
434 fn get_mixed_radix_power2(len: usize) -> Arc<dyn Fft<f32>> {
435 match len {
436 8 => Arc::new(Butterfly8::new( FftDirection::Forward)),
437 16 => Arc::new(Butterfly16::new(FftDirection::Forward)),
438 32 => Arc::new(Butterfly32::new(FftDirection::Forward)),
439 _ => {
440 let zeroes = len.trailing_zeros();
441 assert!(zeroes % 2 == 0);
442 let half_zeroes = zeroes / 2;
443 let inner = get_mixed_radix_power2(1 << half_zeroes);
444 Arc::new(MixedRadix::new(Arc::clone(&inner), inner))
445 }
446 }
447 }
448
449 /// Times just the FFT execution (not allocation and pre-calculation)
450 /// for a given length, specific to Rader's algorithm
451 fn bench_mixed_radix_power2(b: &mut Bencher, len: usize) {
452 let fft = get_mixed_radix_power2(len);
453
454 let mut buffer = vec![Zero::zero(); len];
455 let mut scratch = vec![Zero::zero(); fft.get_inplace_scratch_len()];
456 b.iter(|| {
457 fft.process_with_scratch(&mut buffer, &mut scratch);
458 });
459 }
460
461 #[bench] fn mixed_radix_power2__00000256(b: &mut Bencher) { bench_mixed_radix_power2(b, 256); }
462 #[bench] fn mixed_radix_power2__00001024(b: &mut Bencher) { bench_mixed_radix_power2(b, 1024); }
463 #[bench] fn mixed_radix_power2__00004096(b: &mut Bencher) { bench_mixed_radix_power2(b, 4096); }
464 #[bench] fn mixed_radix_power2__00065536(b: &mut Bencher) { bench_mixed_radix_power2(b, 65536); }
465 #[bench] fn mixed_radix_power2__01048576(b: &mut Bencher) { bench_mixed_radix_power2(b, 1048576); }
466 #[bench] fn mixed_radix_power2__16777216(b: &mut Bencher) { bench_mixed_radix_power2(b, 16777216); }
467
468
469 fn get_mixed_radix_inline_power2(len: usize) -> Arc<dyn Fft<f32>> {
470 match len {
471 8 => Arc::new(Butterfly8::new( FftDirection::Forward)),
472 16 => Arc::new(Butterfly16::new(FftDirection::Forward)),
473 32 => Arc::new(Butterfly32::new(FftDirection::Forward)),
474 _ => {
475 let zeroes = len.trailing_zeros();
476 assert!(zeroes % 2 == 0);
477 let half_zeroes = zeroes / 2;
478 let inner = get_mixed_radix_inline_power2(1 << half_zeroes);
479 Arc::new(MixedRadix::new(Arc::clone(&inner), inner))
480 }
481 }
482 }
483
484 /// Times just the FFT execution (not allocation and pre-calculation)
485 /// for a given length, specific to Rader's algorithm
486 fn bench_mixed_radix_inline_power2(b: &mut Bencher, len: usize) {
487 let fft = get_mixed_radix_inline_power2(len);
488
489 let mut buffer = vec![Zero::zero(); len];
490 let mut scratch = vec![Zero::zero(); fft.get_inplace_scratch_len()];
491 b.iter(|| {
492 fft.process_with_scratch(&mut buffer, &mut scratch);
493 });
494 }
495
496 #[bench] fn mixed_radix_power2_inline__00000256(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 256); }
497 #[bench] fn mixed_radix_power2_inline__00001024(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 1024); }
498 #[bench] fn mixed_radix_power2_inline__00004096(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 4096); }
499 #[bench] fn mixed_radix_power2_inline__00065536(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 65536); }
500 #[bench] fn mixed_radix_power2_inline__01048576(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 1048576); }
501 #[bench] fn mixed_radix_power2_inline__16777216(b: &mut Bencher) { bench_mixed_radix_inline_power2(b, 16777216); }
502
503 /// Times just the FFT execution (not allocation and pre-calculation)
504 /// for a given length
505 fn bench_butterfly32(b: &mut Bencher, len: usize) {
506
507 let mut planner = rustfft::FftPlanner::new();
508 let fft: Arc<dyn Fft<f32>> = planner.plan_fft_forward(len);
509
510 let mut buffer = vec![Complex::zero(); len * 10];
511 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
512 b.iter(|| { fft.process_with_scratch(&mut buffer, &mut scratch); });
513 }
514
515 #[bench] fn butterfly32_02(b: &mut Bencher) { bench_butterfly32(b, 2); }
516 #[bench] fn butterfly32_03(b: &mut Bencher) { bench_butterfly32(b, 3); }
517 #[bench] fn butterfly32_04(b: &mut Bencher) { bench_butterfly32(b, 4); }
518 #[bench] fn butterfly32_05(b: &mut Bencher) { bench_butterfly32(b, 5); }
519 #[bench] fn butterfly32_06(b: &mut Bencher) { bench_butterfly32(b, 6); }
520 #[bench] fn butterfly32_07(b: &mut Bencher) { bench_butterfly32(b, 7); }
521 #[bench] fn butterfly32_08(b: &mut Bencher) { bench_butterfly32(b, 8); }
522 #[bench] fn butterfly32_09(b: &mut Bencher) { bench_butterfly32(b, 9); }
523 #[bench] fn butterfly32_11(b: &mut Bencher) { bench_butterfly32(b, 11); }
524 #[bench] fn butterfly32_12(b: &mut Bencher) { bench_butterfly32(b, 12); }
525 #[bench] fn butterfly32_16(b: &mut Bencher) { bench_butterfly32(b, 16); }
526 #[bench] fn butterfly32_24(b: &mut Bencher) { bench_butterfly32(b, 24); }
527 #[bench] fn butterfly32_27(b: &mut Bencher) { bench_butterfly32(b, 27); }
528 #[bench] fn butterfly32_32(b: &mut Bencher) { bench_butterfly32(b, 32); }
529 #[bench] fn butterfly32_36(b: &mut Bencher) { bench_butterfly32(b, 36); }
530 #[bench] fn butterfly32_48(b: &mut Bencher) { bench_butterfly32(b, 48); }
531 #[bench] fn butterfly32_54(b: &mut Bencher) { bench_butterfly32(b, 54); }
532 #[bench] fn butterfly32_64(b: &mut Bencher) { bench_butterfly32(b, 64); }
533 #[bench] fn butterfly32_72(b: &mut Bencher) { bench_butterfly32(b, 72); }
534 #[bench] fn butterfly32_128(b: &mut Bencher) { bench_butterfly32(b, 128); }
535 #[bench] fn butterfly32_256(b: &mut Bencher) { bench_butterfly32(b, 256); }
536 #[bench] fn butterfly32_512(b: &mut Bencher) { bench_butterfly32(b, 512); }
537
538 /// Times just the FFT execution (not allocation and pre-calculation)
539 /// for a given length
540 fn bench_butterfly64(b: &mut Bencher, len: usize) {
541
542 let mut planner = rustfft::FftPlanner::new();
543 let fft: Arc<dyn Fft<f64>> = planner.plan_fft_forward(len);
544
545 let mut buffer = vec![Complex::zero(); len * 10];
546 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
547 b.iter(|| { fft.process_with_scratch(&mut buffer, &mut scratch); });
548 }
549
550 #[bench] fn butterfly64_02(b: &mut Bencher) { bench_butterfly64(b, 2); }
551 #[bench] fn butterfly64_03(b: &mut Bencher) { bench_butterfly64(b, 3); }
552 #[bench] fn butterfly64_04(b: &mut Bencher) { bench_butterfly64(b, 4); }
553 #[bench] fn butterfly64_05(b: &mut Bencher) { bench_butterfly64(b, 5); }
554 #[bench] fn butterfly64_06(b: &mut Bencher) { bench_butterfly64(b, 6); }
555 #[bench] fn butterfly64_07(b: &mut Bencher) { bench_butterfly64(b, 7); }
556 #[bench] fn butterfly64_08(b: &mut Bencher) { bench_butterfly64(b, 8); }
557 #[bench] fn butterfly64_09(b: &mut Bencher) { bench_butterfly64(b, 9); }
558 #[bench] fn butterfly64_11(b: &mut Bencher) { bench_butterfly64(b, 11); }
559 #[bench] fn butterfly64_12(b: &mut Bencher) { bench_butterfly64(b, 12); }
560 #[bench] fn butterfly64_16(b: &mut Bencher) { bench_butterfly64(b, 16); }
561 #[bench] fn butterfly64_18(b: &mut Bencher) { bench_butterfly64(b, 18); }
562 #[bench] fn butterfly64_24(b: &mut Bencher) { bench_butterfly64(b, 24); }
563 #[bench] fn butterfly64_27(b: &mut Bencher) { bench_butterfly64(b, 27); }
564 #[bench] fn butterfly64_32(b: &mut Bencher) { bench_butterfly64(b, 32); }
565 #[bench] fn butterfly64_36(b: &mut Bencher) { bench_butterfly64(b, 36); }
566 #[bench] fn butterfly64_64(b: &mut Bencher) { bench_butterfly64(b, 64); }
567 #[bench] fn butterfly64_128(b: &mut Bencher) { bench_butterfly64(b, 128); }
568 #[bench] fn butterfly64_256(b: &mut Bencher) { bench_butterfly64(b, 256); }
569 #[bench] fn butterfly64_512(b: &mut Bencher) { bench_butterfly64(b, 512); }