1 #![feature(test)]
2 extern crate rustfft;
3 extern crate test;
4
5 use rustfft::num_complex::Complex;
6 use rustfft::num_traits::Zero;
7 use rustfft::Fft;
8 use std::sync::Arc;
9 use test::Bencher;
10
11
12 /// Times just the FFT execution (not allocation and pre-calculation)
13 /// for a given length
bench_planned_f32(b: &mut Bencher, len: usize)14 fn bench_planned_f32(b: &mut Bencher, len: usize) {
15 let mut planner = rustfft::FftPlannerSse::new().unwrap();
16 let fft: Arc<dyn Fft<f32>> = planner.plan_fft_forward(len);
17 assert_eq!(fft.len(), len);
18
19 let mut buffer = vec![Complex::zero(); len];
20 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
21 b.iter(|| {
22 fft.process_with_scratch(&mut buffer, &mut scratch);
23 });
24 }
bench_planned_f64(b: &mut Bencher, len: usize)25 fn bench_planned_f64(b: &mut Bencher, len: usize) {
26 let mut planner = rustfft::FftPlannerSse::new().unwrap();
27 let fft: Arc<dyn Fft<f64>> = planner.plan_fft_forward(len);
28 assert_eq!(fft.len(), len);
29
30 let mut buffer = vec![Complex::zero(); len];
31 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
32 b.iter(|| {
33 fft.process_with_scratch(&mut buffer, &mut scratch);
34 });
35 }
36
37 /// Times just the FFT execution (not allocation and pre-calculation)
38 /// for a given length.
39 /// Run the fft on a 10*len vector, similar to how the butterflies are often used.
bench_planned_multi_f32(b: &mut Bencher, len: usize)40 fn bench_planned_multi_f32(b: &mut Bencher, len: usize) {
41 let mut planner = rustfft::FftPlannerSse::new().unwrap();
42 let fft: Arc<dyn Fft<f32>> = planner.plan_fft_forward(len);
43
44 let mut buffer = vec![Complex::zero(); len * 10];
45 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
46 b.iter(|| {
47 fft.process_with_scratch(&mut buffer, &mut scratch);
48 });
49 }
bench_planned_multi_f64(b: &mut Bencher, len: usize)50 fn bench_planned_multi_f64(b: &mut Bencher, len: usize) {
51 let mut planner = rustfft::FftPlannerSse::new().unwrap();
52 let fft: Arc<dyn Fft<f64>> = planner.plan_fft_forward(len);
53
54 let mut buffer = vec![Complex::zero(); len * 10];
55 let mut scratch = vec![Complex::zero(); fft.get_inplace_scratch_len()];
56 b.iter(|| {
57 fft.process_with_scratch(&mut buffer, &mut scratch);
58 });
59 }
60
61 // All butterflies
butterfly32_02(b: &mut Bencher)62 #[bench] fn butterfly32_02(b: &mut Bencher) { bench_planned_multi_f32(b, 2);}
butterfly32_03(b: &mut Bencher)63 #[bench] fn butterfly32_03(b: &mut Bencher) { bench_planned_multi_f32(b, 3);}
butterfly32_04(b: &mut Bencher)64 #[bench] fn butterfly32_04(b: &mut Bencher) { bench_planned_multi_f32(b, 4);}
butterfly32_05(b: &mut Bencher)65 #[bench] fn butterfly32_05(b: &mut Bencher) { bench_planned_multi_f32(b, 5);}
butterfly32_06(b: &mut Bencher)66 #[bench] fn butterfly32_06(b: &mut Bencher) { bench_planned_multi_f32(b, 6);}
butterfly32_07(b: &mut Bencher)67 #[bench] fn butterfly32_07(b: &mut Bencher) { bench_planned_multi_f32(b, 7);}
butterfly32_08(b: &mut Bencher)68 #[bench] fn butterfly32_08(b: &mut Bencher) { bench_planned_multi_f32(b, 8);}
butterfly32_09(b: &mut Bencher)69 #[bench] fn butterfly32_09(b: &mut Bencher) { bench_planned_multi_f32(b, 9);}
butterfly32_10(b: &mut Bencher)70 #[bench] fn butterfly32_10(b: &mut Bencher) { bench_planned_multi_f32(b, 10);}
butterfly32_11(b: &mut Bencher)71 #[bench] fn butterfly32_11(b: &mut Bencher) { bench_planned_multi_f32(b, 11);}
butterfly32_12(b: &mut Bencher)72 #[bench] fn butterfly32_12(b: &mut Bencher) { bench_planned_multi_f32(b, 12);}
butterfly32_13(b: &mut Bencher)73 #[bench] fn butterfly32_13(b: &mut Bencher) { bench_planned_multi_f32(b, 13);}
butterfly32_15(b: &mut Bencher)74 #[bench] fn butterfly32_15(b: &mut Bencher) { bench_planned_multi_f32(b, 15);}
butterfly32_16(b: &mut Bencher)75 #[bench] fn butterfly32_16(b: &mut Bencher) { bench_planned_multi_f32(b, 16);}
butterfly32_17(b: &mut Bencher)76 #[bench] fn butterfly32_17(b: &mut Bencher) { bench_planned_multi_f32(b, 17);}
butterfly32_19(b: &mut Bencher)77 #[bench] fn butterfly32_19(b: &mut Bencher) { bench_planned_multi_f32(b, 19);}
butterfly32_23(b: &mut Bencher)78 #[bench] fn butterfly32_23(b: &mut Bencher) { bench_planned_multi_f32(b, 23);}
butterfly32_29(b: &mut Bencher)79 #[bench] fn butterfly32_29(b: &mut Bencher) { bench_planned_multi_f32(b, 29);}
butterfly32_31(b: &mut Bencher)80 #[bench] fn butterfly32_31(b: &mut Bencher) { bench_planned_multi_f32(b, 31);}
butterfly32_32(b: &mut Bencher)81 #[bench] fn butterfly32_32(b: &mut Bencher) { bench_planned_multi_f32(b, 32);}
82
butterfly64_02(b: &mut Bencher)83 #[bench] fn butterfly64_02(b: &mut Bencher) { bench_planned_multi_f64(b, 2);}
butterfly64_03(b: &mut Bencher)84 #[bench] fn butterfly64_03(b: &mut Bencher) { bench_planned_multi_f64(b, 3);}
butterfly64_04(b: &mut Bencher)85 #[bench] fn butterfly64_04(b: &mut Bencher) { bench_planned_multi_f64(b, 4);}
butterfly64_05(b: &mut Bencher)86 #[bench] fn butterfly64_05(b: &mut Bencher) { bench_planned_multi_f64(b, 5);}
butterfly64_06(b: &mut Bencher)87 #[bench] fn butterfly64_06(b: &mut Bencher) { bench_planned_multi_f64(b, 6);}
butterfly64_07(b: &mut Bencher)88 #[bench] fn butterfly64_07(b: &mut Bencher) { bench_planned_multi_f64(b, 7);}
butterfly64_08(b: &mut Bencher)89 #[bench] fn butterfly64_08(b: &mut Bencher) { bench_planned_multi_f64(b, 8);}
butterfly64_09(b: &mut Bencher)90 #[bench] fn butterfly64_09(b: &mut Bencher) { bench_planned_multi_f64(b, 9);}
butterfly64_10(b: &mut Bencher)91 #[bench] fn butterfly64_10(b: &mut Bencher) { bench_planned_multi_f64(b, 10);}
butterfly64_11(b: &mut Bencher)92 #[bench] fn butterfly64_11(b: &mut Bencher) { bench_planned_multi_f64(b, 11);}
butterfly64_12(b: &mut Bencher)93 #[bench] fn butterfly64_12(b: &mut Bencher) { bench_planned_multi_f64(b, 12);}
butterfly64_13(b: &mut Bencher)94 #[bench] fn butterfly64_13(b: &mut Bencher) { bench_planned_multi_f64(b, 13);}
butterfly64_15(b: &mut Bencher)95 #[bench] fn butterfly64_15(b: &mut Bencher) { bench_planned_multi_f64(b, 15);}
butterfly64_16(b: &mut Bencher)96 #[bench] fn butterfly64_16(b: &mut Bencher) { bench_planned_multi_f64(b, 16);}
butterfly64_17(b: &mut Bencher)97 #[bench] fn butterfly64_17(b: &mut Bencher) { bench_planned_multi_f64(b, 17);}
butterfly64_19(b: &mut Bencher)98 #[bench] fn butterfly64_19(b: &mut Bencher) { bench_planned_multi_f64(b, 19);}
butterfly64_23(b: &mut Bencher)99 #[bench] fn butterfly64_23(b: &mut Bencher) { bench_planned_multi_f64(b, 23);}
butterfly64_29(b: &mut Bencher)100 #[bench] fn butterfly64_29(b: &mut Bencher) { bench_planned_multi_f64(b, 29);}
butterfly64_31(b: &mut Bencher)101 #[bench] fn butterfly64_31(b: &mut Bencher) { bench_planned_multi_f64(b, 31);}
butterfly64_32(b: &mut Bencher)102 #[bench] fn butterfly64_32(b: &mut Bencher) { bench_planned_multi_f64(b, 32);}
103
104 // Powers of 2
planned32_p2_00000064(b: &mut Bencher)105 #[bench] fn planned32_p2_00000064(b: &mut Bencher) { bench_planned_f32(b, 64); }
planned32_p2_00000128(b: &mut Bencher)106 #[bench] fn planned32_p2_00000128(b: &mut Bencher) { bench_planned_f32(b, 128); }
planned32_p2_00000256(b: &mut Bencher)107 #[bench] fn planned32_p2_00000256(b: &mut Bencher) { bench_planned_f32(b, 256); }
planned32_p2_00000512(b: &mut Bencher)108 #[bench] fn planned32_p2_00000512(b: &mut Bencher) { bench_planned_f32(b, 512); }
planned32_p2_00001024(b: &mut Bencher)109 #[bench] fn planned32_p2_00001024(b: &mut Bencher) { bench_planned_f32(b, 1024); }
planned32_p2_00002048(b: &mut Bencher)110 #[bench] fn planned32_p2_00002048(b: &mut Bencher) { bench_planned_f32(b, 2048); }
planned32_p2_00004096(b: &mut Bencher)111 #[bench] fn planned32_p2_00004096(b: &mut Bencher) { bench_planned_f32(b, 4096); }
planned32_p2_00016384(b: &mut Bencher)112 #[bench] fn planned32_p2_00016384(b: &mut Bencher) { bench_planned_f32(b, 16384); }
planned32_p2_00065536(b: &mut Bencher)113 #[bench] fn planned32_p2_00065536(b: &mut Bencher) { bench_planned_f32(b, 65536); }
planned32_p2_01048576(b: &mut Bencher)114 #[bench] fn planned32_p2_01048576(b: &mut Bencher) { bench_planned_f32(b, 1048576); }
115
planned64_p2_00000064(b: &mut Bencher)116 #[bench] fn planned64_p2_00000064(b: &mut Bencher) { bench_planned_f64(b, 64); }
planned64_p2_00000128(b: &mut Bencher)117 #[bench] fn planned64_p2_00000128(b: &mut Bencher) { bench_planned_f64(b, 128); }
planned64_p2_00000256(b: &mut Bencher)118 #[bench] fn planned64_p2_00000256(b: &mut Bencher) { bench_planned_f64(b, 256); }
planned64_p2_00000512(b: &mut Bencher)119 #[bench] fn planned64_p2_00000512(b: &mut Bencher) { bench_planned_f64(b, 512); }
planned64_p2_00001024(b: &mut Bencher)120 #[bench] fn planned64_p2_00001024(b: &mut Bencher) { bench_planned_f64(b, 1024); }
planned64_p2_00002048(b: &mut Bencher)121 #[bench] fn planned64_p2_00002048(b: &mut Bencher) { bench_planned_f64(b, 2048); }
planned64_p2_00004096(b: &mut Bencher)122 #[bench] fn planned64_p2_00004096(b: &mut Bencher) { bench_planned_f64(b, 4096); }
planned64_p2_00016384(b: &mut Bencher)123 #[bench] fn planned64_p2_00016384(b: &mut Bencher) { bench_planned_f64(b, 16384); }
planned64_p2_00065536(b: &mut Bencher)124 #[bench] fn planned64_p2_00065536(b: &mut Bencher) { bench_planned_f64(b, 65536); }
planned64_p2_01048576(b: &mut Bencher)125 #[bench] fn planned64_p2_01048576(b: &mut Bencher) { bench_planned_f64(b, 1048576); }
126
127
128 // Powers of 7
planned32_p7_00343(b: &mut Bencher)129 #[bench] fn planned32_p7_00343(b: &mut Bencher) { bench_planned_f32(b, 343); }
planned32_p7_02401(b: &mut Bencher)130 #[bench] fn planned32_p7_02401(b: &mut Bencher) { bench_planned_f32(b, 2401); }
planned32_p7_16807(b: &mut Bencher)131 #[bench] fn planned32_p7_16807(b: &mut Bencher) { bench_planned_f32(b, 16807); }
132
planned64_p7_00343(b: &mut Bencher)133 #[bench] fn planned64_p7_00343(b: &mut Bencher) { bench_planned_f64(b, 343); }
planned64_p7_02401(b: &mut Bencher)134 #[bench] fn planned64_p7_02401(b: &mut Bencher) { bench_planned_f64(b, 2401); }
planned64_p7_16807(b: &mut Bencher)135 #[bench] fn planned64_p7_16807(b: &mut Bencher) { bench_planned_f64(b, 16807); }
136
137 // Prime lengths
planned32_prime_0149(b: &mut Bencher)138 #[bench] fn planned32_prime_0149(b: &mut Bencher) { bench_planned_f32(b, 149); }
planned32_prime_0151(b: &mut Bencher)139 #[bench] fn planned32_prime_0151(b: &mut Bencher) { bench_planned_f32(b, 151); }
planned32_prime_0251(b: &mut Bencher)140 #[bench] fn planned32_prime_0251(b: &mut Bencher) { bench_planned_f32(b, 251); }
planned32_prime_0257(b: &mut Bencher)141 #[bench] fn planned32_prime_0257(b: &mut Bencher) { bench_planned_f32(b, 257); }
planned32_prime_2017(b: &mut Bencher)142 #[bench] fn planned32_prime_2017(b: &mut Bencher) { bench_planned_f32(b, 2017); }
planned32_prime_2879(b: &mut Bencher)143 #[bench] fn planned32_prime_2879(b: &mut Bencher) { bench_planned_f32(b, 2879); }
planned32_prime_65521(b: &mut Bencher)144 #[bench] fn planned32_prime_65521(b: &mut Bencher) { bench_planned_f32(b, 65521); }
planned32_prime_746497(b: &mut Bencher)145 #[bench] fn planned32_prime_746497(b: &mut Bencher) { bench_planned_f32(b,746497); }
146
planned64_prime_0149(b: &mut Bencher)147 #[bench] fn planned64_prime_0149(b: &mut Bencher) { bench_planned_f64(b, 149); }
planned64_prime_0151(b: &mut Bencher)148 #[bench] fn planned64_prime_0151(b: &mut Bencher) { bench_planned_f64(b, 151); }
planned64_prime_0251(b: &mut Bencher)149 #[bench] fn planned64_prime_0251(b: &mut Bencher) { bench_planned_f64(b, 251); }
planned64_prime_0257(b: &mut Bencher)150 #[bench] fn planned64_prime_0257(b: &mut Bencher) { bench_planned_f64(b, 257); }
planned64_prime_2017(b: &mut Bencher)151 #[bench] fn planned64_prime_2017(b: &mut Bencher) { bench_planned_f64(b, 2017); }
planned64_prime_2879(b: &mut Bencher)152 #[bench] fn planned64_prime_2879(b: &mut Bencher) { bench_planned_f64(b, 2879); }
planned64_prime_65521(b: &mut Bencher)153 #[bench] fn planned64_prime_65521(b: &mut Bencher) { bench_planned_f64(b, 65521); }
planned64_prime_746497(b: &mut Bencher)154 #[bench] fn planned64_prime_746497(b: &mut Bencher) { bench_planned_f64(b,746497); }
155
156 // small mixed composites
planned32_composite_000018(b: &mut Bencher)157 #[bench] fn planned32_composite_000018(b: &mut Bencher) { bench_planned_f32(b, 00018); }
planned32_composite_000360(b: &mut Bencher)158 #[bench] fn planned32_composite_000360(b: &mut Bencher) { bench_planned_f32(b, 00360); }
planned32_composite_001200(b: &mut Bencher)159 #[bench] fn planned32_composite_001200(b: &mut Bencher) { bench_planned_f32(b, 01200); }
planned32_composite_044100(b: &mut Bencher)160 #[bench] fn planned32_composite_044100(b: &mut Bencher) { bench_planned_f32(b, 44100); }
planned32_composite_048000(b: &mut Bencher)161 #[bench] fn planned32_composite_048000(b: &mut Bencher) { bench_planned_f32(b, 48000); }
planned32_composite_046656(b: &mut Bencher)162 #[bench] fn planned32_composite_046656(b: &mut Bencher) { bench_planned_f32(b, 46656); }
163
planned64_composite_000018(b: &mut Bencher)164 #[bench] fn planned64_composite_000018(b: &mut Bencher) { bench_planned_f64(b, 00018); }
planned64_composite_000360(b: &mut Bencher)165 #[bench] fn planned64_composite_000360(b: &mut Bencher) { bench_planned_f64(b, 00360); }
planned64_composite_001200(b: &mut Bencher)166 #[bench] fn planned64_composite_001200(b: &mut Bencher) { bench_planned_f64(b, 01200); }
planned64_composite_044100(b: &mut Bencher)167 #[bench] fn planned64_composite_044100(b: &mut Bencher) { bench_planned_f64(b, 44100); }
planned64_composite_048000(b: &mut Bencher)168 #[bench] fn planned64_composite_048000(b: &mut Bencher) { bench_planned_f64(b, 48000); }
planned64_composite_046656(b: &mut Bencher)169 #[bench] fn planned64_composite_046656(b: &mut Bencher) { bench_planned_f64(b, 46656); }
170
171
172
173