Skip to content

Commit

Permalink
Add simply FFT roundtrip speed test.
Browse files Browse the repository at this point in the history
1 second for 2560x6000 along axis 1
  • Loading branch information
brettviren committed Feb 2, 2024
1 parent e85e8ec commit 2ec31c4
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/fftspeed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy

def roundtrip(wave, size):
nchan, ntick = wave.shape

if size == ntick:
return wave

spec = numpy.fft.fft(wave, axis=1)
spec = numpy.fft.ifftshift(spec)

# note: this is not quite right but good enough for speed
if size < ntick: # downsample
half = (ntick-size)//2
spec = spec[:, half:-half]
else: # upsample
half = (size-ntick)//2
spec = numpy.hstack( (numpy.zeros((nchan,half), dtype=spec.dtype),
spec,
numpy.zeros((nchan,half), dtype=spec.dtype)) )
spec = numpy.fft.fftshift(spec)
wave = numpy.real(numpy.fft.ifft(spec))
return wave * wave.shape[1] / ntick

import timeit
def main(filename, size):
f = numpy.load(filename)
fr = f[f.files[0]]

def runit():
roundtrip(fr, size)

got = timeit.timeit(runit, number=10)
print(got)

if '__main__' == __name__:
import sys
try:
size = int(sys.argv[2])
except IndexError:
size = 6144

main(sys.argv[1], int(sys.argv[2]))

0 comments on commit 2ec31c4

Please sign in to comment.