keijiro/BurstFFT

Parallel is faster than serial for larger fft size

Closed this issue · 1 comments

Thanks for the excellent code keijiro! FWIW, as I was testing your code inside my application I noticed that as fft size continues to be increased the parallel version does eventually become faster than the serial version. For me this was around 16,384 samples (with leak detection off, burst safety checks off, and jobs debugger disabled). I am sharing this in case you want to update your README.

Parallel benchmarks...

BurstFft (length=1024) Millisecond Median:0.10 Min:0.10 Max:0.11 Avg:0.10 Std:0.01 SampleCount: 9 Sum: 0.90
BurstFft (length=8192) Millisecond Median:0.23 Min:0.22 Max:0.24 Avg:0.23 Std:0.00 SampleCount: 9 Sum: 2.04
BurstFft (length=16384) Millisecond Median:0.29 Min:0.28 Max:0.31 Avg:0.29 Std:0.01 SampleCount: 9 Sum: 2.64
BurstFft (length=65536) Millisecond Median:0.53 Min:0.53 Max:0.55 Avg:0.54 Std:0.01 SampleCount: 9 Sum: 4.82

Serial benchmarks...

BurstFft (length=1024) Millisecond Median:0.03 Min:0.03 Max:0.03 Avg:0.03 Std:0.00 SampleCount: 9 Sum: 0.23
BurstFft (length=8192) Millisecond Median:0.14 Min:0.14 Max:0.14 Avg:0.14 Std:0.00 SampleCount: 9 Sum: 1.22
BurstFft (length=16384) Millisecond Median:0.28 Min:0.28 Max:0.28 Avg:0.28 Std:0.00 SampleCount: 9 Sum: 2.49
BurstFft (length=65536) Millisecond Median:1.17 Min:1.17 Max:1.17 Avg:1.17 Std:0.00 SampleCount: 9 Sum: 10.52

Test code...

    [Test, Performance]
    public void BurstFft()
    {
        int[] LENGTHS = new int[] { 1024, 8192, 16384, 65536 };
        for (var i = 0; i < LENGTHS.Length; ++i) {
            var x = new float[LENGTHS[i]];
            var spectrum = new float[LENGTHS[i]];
            var fft = new BurstFft(x.Length);
            var input = new NativeArray<float>(x.Length, Allocator.Persistent);
            Measure.Method(() =>
            {
                AudioListener.GetOutputData(x, 0);
                input.CopyFrom(x);
                fft.Transform(input);
                fft.Spectrum.CopyTo(spectrum);
            }).SampleGroup($"BurstFft (length={LENGTHS[i]})").Run();
            input.Dispose();
            fft.Dispose();
        }
    }

Thanks for sharing the information. Interesting.