github.com/noriah/catnip@v1.8.5/fft/fft_test.go (about)

     1  package fft
     2  
     3  import "testing"
     4  
     5  func Benchmark(b *testing.B) {
     6  	if FFTW {
     7  		b.Log("Benchmarking FFTW.")
     8  	} else {
     9  		b.Log("Benchmarking gonum (built without cgo).")
    10  	}
    11  
    12  	reals := generateReals()
    13  	cmplx := make([]complex128, len(reals)/2+1)
    14  	fftpl := Plan{
    15  		input:  reals,
    16  		output: cmplx,
    17  	}
    18  
    19  	b.ResetTimer()
    20  
    21  	for i := 0; i < b.N; i++ {
    22  		fftpl.Execute()
    23  	}
    24  }
    25  
    26  // Adapted from https://github.com/project-gemmi/benchmarking-fft/blob/master/1d-r.cpp
    27  
    28  const numReals = 44100
    29  
    30  func generateReals() []float64 {
    31  	input := make([]float64, numReals)
    32  
    33  	c := 3.1
    34  	for i := range input {
    35  		c += 0.3
    36  		input[i] = 2*c - c*c
    37  	}
    38  
    39  	return input
    40  }