replace numpyfft with scipyfft for better performance
it seems that scipy.fft is faster than numpy fft sources
1 ) https://stackoverflow.com/questions/6363154/what-is-the-difference-between-numpy-fft-and-scipy-fftpack 2 ) https://medium.com/@corentin.soubeiran/whos-the-most-efficient-fft-techniques-in-python-boosting-performance-and-understanding-d19b6641d6d8
compared to other avialble options numpy fft and scipy fft seem to have higher accuracy as well
@Sauravroy34 interesting, thanks. Do you have measurements for the 1D transform we use as well?
sure , i could not find data for 1 d in internet so i decided of making one
import numpy as np
import scipy.fft
import timeit
import matplotlib.pyplot as plt
# Different sizes of input signals
sizes = [2**i for i in range(5, 21)]
import pyfftw
def benchmark_fft(lib, size):
x = np.random.random(size)
if lib == 'numpy':
return timeit.timeit(lambda: pyfftw.interfaces.numpy_fft.fft(x), number=10) / 10
elif lib == 'scipy':
return timeit.timeit(lambda: pyfftw.interfaces.scipy_fft.fft(x), number=10) / 10
numpy_times = [benchmark_fft('numpy', size) for size in sizes]
scipy_times = [benchmark_fft('scipy', size) for size in sizes]
plt.figure(figsize=(10, 6))
plt.plot(sizes, numpy_times, label='pyfftw NumPy FFT', marker='o')
plt.plot(sizes, scipy_times, label='pyfftw SciPy FFT', marker='s')
plt.xlabel('Input Size')
plt.ylabel('Time (seconds)')
plt.xscale('log')
plt.yscale('log')
plt.legend()
plt.title('Comparison of FFT Computation Time: NumPy vs SciPy')
plt.grid(True, which='both', linestyle='--', linewidth=0.5)
plt.show()
using pyfftw interfaces
import numpy as np
import scipy.fft
import timeit
import matplotlib.pyplot as plt
# Different sizes of input signals
sizes = [2**i for i in range(5, 21)]
def benchmark_fft(lib, size):
x = np.random.random(size)
if lib == 'numpy':
return timeit.timeit(lambda: np.fft.fft(x), number=10) / 10
elif lib == 'scipy':
return timeit.timeit(lambda: scipy.fft.fft(x), number=10) / 10
numpy_times = [benchmark_fft('numpy', size) for size in sizes]
scipy_times = [benchmark_fft('scipy', size) for size in sizes]
plt.figure(figsize=(10, 6))
plt.plot(sizes, numpy_times, label='NumPy FFT', marker='o')
plt.plot(sizes, scipy_times, label='SciPy FFT', marker='s')
plt.xlabel('Input Size')
plt.ylabel('Time (seconds)')
plt.xscale('log')
plt.yscale('log')
plt.legend()
plt.title('Comparison of FFT Computation Time: NumPy vs SciPy')
plt.grid(True, which='both', linestyle='--', linewidth=0.5)
plt.show()
normal scipy fft and numpy fft
@Sauravroy34 would you mind re-running the benchmark inverting the order of the calls to numpy and scipy?
Just as a sanity check
@Sauravroy34 would you mind re-running the benchmark inverting the order of the calls to numpy and scipy?
Just as a sanity check
inverting the calls seems to have reverse effect on plots it might be due to some caching effect i will try to create a uniform benchmark for both of them and post update here
@matteobachetti in this comment the benchmark was conducted
https://github.com/StingraySoftware/stingray/issues/369#issuecomment-603697909
i have conducted few test myself here is the notebook https://github.com/Sauravroy34/Benchmark_test_for_scipy_and_numpy