mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-06-04 01:28:23 -04:00
modified time benchmark to repeat same buffer over and over to avoid IO bottlenecks and get more consistent numbers.
This commit is contained in:
parent
471803ca08
commit
8ac63adc77
39
kiss_fft.c
39
kiss_fft.c
@ -206,6 +206,43 @@ void bfly3(
|
|||||||
}while(--m);
|
}while(--m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bfly5(
|
||||||
|
kiss_fft_cpx * Fout,
|
||||||
|
int fstride,
|
||||||
|
const kiss_fft_state * st,
|
||||||
|
int m
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int u,k,q1,q;
|
||||||
|
const int p=5;
|
||||||
|
kiss_fft_cpx * scratch = st->scratch;
|
||||||
|
kiss_fft_cpx * twiddles = st->twiddles;
|
||||||
|
kiss_fft_cpx t;
|
||||||
|
int Norig = st->nfft;
|
||||||
|
|
||||||
|
for ( u=0; u<m; ++u ) {
|
||||||
|
k=u;
|
||||||
|
for ( q1=0 ; q1<p ; ++q1 ) {
|
||||||
|
scratch[q1] = Fout[ k ];
|
||||||
|
C_FIXDIV(scratch[q1],p);
|
||||||
|
k += m;
|
||||||
|
}
|
||||||
|
|
||||||
|
k=u;
|
||||||
|
for ( q1=0 ; q1<p ; ++q1 ) {
|
||||||
|
int twidx=0;
|
||||||
|
Fout[ k ] = scratch[0];
|
||||||
|
for (q=1;q<p;++q ) {
|
||||||
|
twidx += fstride * k;
|
||||||
|
if (twidx>=Norig) twidx-=Norig;
|
||||||
|
C_MUL(t,scratch[q] , twiddles[twidx] );
|
||||||
|
C_ADDTO( Fout[ k ] ,t);
|
||||||
|
}
|
||||||
|
k += m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* perform the butterfly for one stage of a mixed radix FFT */
|
/* perform the butterfly for one stage of a mixed radix FFT */
|
||||||
void bfly_generic(
|
void bfly_generic(
|
||||||
kiss_fft_cpx * Fout,
|
kiss_fft_cpx * Fout,
|
||||||
@ -268,6 +305,7 @@ void fft_work(
|
|||||||
case 2: bfly2(Fout,fstride,st,m); break;
|
case 2: bfly2(Fout,fstride,st,m); break;
|
||||||
case 3: bfly3(Fout,fstride,st,m); break;
|
case 3: bfly3(Fout,fstride,st,m); break;
|
||||||
case 4: bfly4(Fout,fstride,st,m); break;
|
case 4: bfly4(Fout,fstride,st,m); break;
|
||||||
|
case 5: bfly5(Fout,fstride,st,m); break;
|
||||||
default: bfly_generic(Fout,fstride,st,m,p); break;
|
default: bfly_generic(Fout,fstride,st,m,p); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,7 +342,6 @@ void * kiss_fft_alloc(int nfft,int inverse_fft)
|
|||||||
st->scratch = (kiss_fft_cpx*)(st->tmpbuf + nfft);
|
st->scratch = (kiss_fft_cpx*)(st->tmpbuf + nfft);
|
||||||
st->factors = (int*)(st->scratch + nfft); /* just after tmpbuf*/
|
st->factors = (int*)(st->scratch + nfft); /* just after tmpbuf*/
|
||||||
|
|
||||||
|
|
||||||
for (i=0;i<nfft;++i) {
|
for (i=0;i<nfft;++i) {
|
||||||
const double pi=3.14159265358979323846264338327;
|
const double pi=3.14159265358979323846264338327;
|
||||||
double phase = ( 2*pi /nfft ) * i;
|
double phase = ( 2*pi /nfft ) * i;
|
||||||
|
@ -28,25 +28,26 @@ endif
|
|||||||
$(UTIL): $(UTILSRC)
|
$(UTIL): $(UTILSRC)
|
||||||
gcc -o $@ $(CFLAGS) $(TYPEFLAGS) $(UTILSRC)
|
gcc -o $@ $(CFLAGS) $(TYPEFLAGS) $(UTILSRC)
|
||||||
|
|
||||||
RANDDAT=rand_$(DATATYPE)_$(NUMFFTS)_$(NFFT).dat
|
RANDDAT=rand_$(DATATYPE)_$(NFFT).dat
|
||||||
$(RANDDAT):
|
$(RANDDAT):
|
||||||
./rand_fft_data.py -n $(NUMFFTS) -N $(NFFT) -t $(DATATYPE) > $(RANDDAT)
|
./rand_fft_data.py -n 1 -N $(NFFT) -t $(DATATYPE) > $(RANDDAT)
|
||||||
|
|
||||||
time: all $(RANDDAT)
|
time: all $(RANDDAT)
|
||||||
@echo
|
@echo
|
||||||
@echo -n "#### timing $(NUMFFTS) x $(NFFT) point FFTs. "; factor $(NFFT)
|
@echo -n "#### timing $(NUMFFTS) x $(NFFT) point FFTs. "; factor $(NFFT)
|
||||||
@if [ -x ~/fftw/st ] && [ $(DATATYPE) == "double" ]; then \
|
@if [ -x ~/fftw/st ] && [ $(DATATYPE) == "double" ]; then \
|
||||||
echo "#### FFTW FFT $(DATATYPE)"; \
|
echo "#### FFTW FFT $(DATATYPE)"; \
|
||||||
time ~/fftw/st -n $(NFFT) < $(RANDDAT) > /dev/null;\
|
time ~/fftw/st -x $(NUMFFTS) -n $(NFFT) < $(RANDDAT) > /dev/null;\
|
||||||
fi
|
fi
|
||||||
@echo "#### KISS FFT $(DATATYPE)"
|
@echo "#### KISS FFT $(DATATYPE)"
|
||||||
@time ./$(UTIL) -n $(NFFT) < $(RANDDAT) > /dev/null
|
@time ./$(UTIL) -x $(NUMFFTS) -n $(NFFT) < $(RANDDAT) > /dev/null
|
||||||
@rm $(RANDDAT)
|
@rm $(RANDDAT)
|
||||||
|
|
||||||
POW2=256 512 1024 2048
|
POW2=256 512 1024 2048
|
||||||
POW3=243 729 2187
|
POW3=243 729 2187
|
||||||
|
POW5=25 125 625
|
||||||
mtime: all
|
mtime: all
|
||||||
@for n in $(POW2) ;do \
|
@for n in $(POW5) ;do \
|
||||||
export NFFT=$$n;make time; \
|
export NFFT=$$n;make time; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
56
test/speedtest.c
Executable file
56
test/speedtest.c
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <fftw3.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc,char ** argv)
|
||||||
|
{
|
||||||
|
int nfft=1024;
|
||||||
|
int isinverse=0;
|
||||||
|
FILE *fin=stdin;
|
||||||
|
FILE *fout=stdout;
|
||||||
|
int times=1,i;
|
||||||
|
|
||||||
|
fftw_complex * in=NULL;
|
||||||
|
fftw_complex * out=NULL;
|
||||||
|
fftw_plan p;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int c = getopt (argc, argv, "n:ix:");
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
switch (c) {
|
||||||
|
case 'n':
|
||||||
|
nfft = atoi (optarg);
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
times = atoi (optarg);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
isinverse = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//fprintf(stderr,"sizeof(fftw_complex) = %d \n" , sizeof(fftw_complex) );
|
||||||
|
fprintf(stderr,"sizeof(fftw_complex[0]) = %d \n" , sizeof((*in)[0]) );
|
||||||
|
|
||||||
|
in=fftw_malloc(sizeof(fftw_complex) * nfft);
|
||||||
|
out=fftw_malloc(sizeof(fftw_complex) * nfft);
|
||||||
|
if ( isinverse )
|
||||||
|
p = fftw_plan_dft_1d(nfft, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
|
||||||
|
else
|
||||||
|
p = fftw_plan_dft_1d(nfft, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
|
||||||
|
|
||||||
|
while ( fread( in , sizeof(fftw_complex) , nfft , fin ) > 0 ) {
|
||||||
|
for (i=0;i<times;++i)
|
||||||
|
fftw_execute(p);
|
||||||
|
fwrite( out , sizeof(fftw_complex) , nfft , fout );
|
||||||
|
}
|
||||||
|
|
||||||
|
fftw_destroy_plan(p);
|
||||||
|
fftw_free(in); fftw_free(out);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -28,25 +28,26 @@ endif
|
|||||||
$(UTIL): $(UTILSRC)
|
$(UTIL): $(UTILSRC)
|
||||||
gcc -o $@ $(CFLAGS) $(TYPEFLAGS) $(UTILSRC)
|
gcc -o $@ $(CFLAGS) $(TYPEFLAGS) $(UTILSRC)
|
||||||
|
|
||||||
RANDDAT=rand_$(DATATYPE)_$(NUMFFTS)_$(NFFT).dat
|
RANDDAT=rand_$(DATATYPE)_$(NFFT).dat
|
||||||
$(RANDDAT):
|
$(RANDDAT):
|
||||||
./rand_fft_data.py -n $(NUMFFTS) -N $(NFFT) -t $(DATATYPE) > $(RANDDAT)
|
./rand_fft_data.py -n 1 -N $(NFFT) -t $(DATATYPE) > $(RANDDAT)
|
||||||
|
|
||||||
time: all $(RANDDAT)
|
time: all $(RANDDAT)
|
||||||
@echo
|
@echo
|
||||||
@echo -n "#### timing $(NUMFFTS) x $(NFFT) point FFTs. "; factor $(NFFT)
|
@echo -n "#### timing $(NUMFFTS) x $(NFFT) point FFTs. "; factor $(NFFT)
|
||||||
@if [ -x ~/fftw/st ] && [ $(DATATYPE) == "double" ]; then \
|
@if [ -x ~/fftw/st ] && [ $(DATATYPE) == "double" ]; then \
|
||||||
echo "#### FFTW FFT $(DATATYPE)"; \
|
echo "#### FFTW FFT $(DATATYPE)"; \
|
||||||
time ~/fftw/st -n $(NFFT) < $(RANDDAT) > /dev/null;\
|
time ~/fftw/st -x $(NUMFFTS) -n $(NFFT) < $(RANDDAT) > /dev/null;\
|
||||||
fi
|
fi
|
||||||
@echo "#### KISS FFT $(DATATYPE)"
|
@echo "#### KISS FFT $(DATATYPE)"
|
||||||
@time ./$(UTIL) -n $(NFFT) < $(RANDDAT) > /dev/null
|
@time ./$(UTIL) -x $(NUMFFTS) -n $(NFFT) < $(RANDDAT) > /dev/null
|
||||||
@rm $(RANDDAT)
|
@rm $(RANDDAT)
|
||||||
|
|
||||||
POW2=256 512 1024 2048
|
POW2=256 512 1024 2048
|
||||||
POW3=243 729 2187
|
POW3=243 729 2187
|
||||||
|
POW5=25 125 625
|
||||||
mtime: all
|
mtime: all
|
||||||
@for n in $(POW2) ;do \
|
@for n in $(POW5) ;do \
|
||||||
export NFFT=$$n;make time; \
|
export NFFT=$$n;make time; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -26,16 +26,20 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fft_file(FILE * fin,FILE * fout,int nfft,int isinverse,int useascii)
|
void fft_file(FILE * fin,FILE * fout,int nfft,int isinverse,int useascii,int times)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
void *st;
|
void *st;
|
||||||
kiss_fft_cpx * buf;
|
kiss_fft_cpx * buf;
|
||||||
|
kiss_fft_cpx * bufout;
|
||||||
|
|
||||||
buf = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * nfft );
|
buf = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * nfft );
|
||||||
|
bufout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx) * nfft );
|
||||||
st = kiss_fft_alloc( nfft ,isinverse );
|
st = kiss_fft_alloc( nfft ,isinverse );
|
||||||
|
|
||||||
while ( fread( buf , sizeof(kiss_fft_cpx) * nfft ,1, fin ) > 0 ) {
|
while ( fread( buf , sizeof(kiss_fft_cpx) * nfft ,1, fin ) > 0 ) {
|
||||||
kiss_fft( st , buf );
|
for (i=0;i<times;++i)
|
||||||
|
kiss_fft_io( st , buf ,bufout);
|
||||||
if (useascii) {
|
if (useascii) {
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<nfft;++i)
|
for (i=0;i<nfft;++i)
|
||||||
@ -46,6 +50,7 @@ void fft_file(FILE * fin,FILE * fout,int nfft,int isinverse,int useascii)
|
|||||||
}
|
}
|
||||||
free(st);
|
free(st);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
free(bufout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char ** argv)
|
int main(int argc,char ** argv)
|
||||||
@ -55,14 +60,16 @@ int main(int argc,char ** argv)
|
|||||||
FILE *fin=stdin;
|
FILE *fin=stdin;
|
||||||
FILE *fout=stdout;
|
FILE *fout=stdout;
|
||||||
int useascii=0;
|
int useascii=0;
|
||||||
|
int times=1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int c=getopt(argc,argv,"n:ia");
|
int c=getopt(argc,argv,"n:iax:");
|
||||||
if (c==-1) break;
|
if (c==-1) break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':useascii=1;break;
|
case 'a':useascii=1;break;
|
||||||
case 'n':nfft = atoi(optarg);break;
|
case 'n':nfft = atoi(optarg);break;
|
||||||
case 'i':isinverse=1;break;
|
case 'i':isinverse=1;break;
|
||||||
|
case 'x':times=atoi(optarg);break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +85,7 @@ int main(int argc,char ** argv)
|
|||||||
++optind;
|
++optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
fft_file(fin,fout,nfft,isinverse,useascii);
|
fft_file(fin,fout,nfft,isinverse,useascii,times);
|
||||||
|
|
||||||
if (fout!=stdout) fclose(fout);
|
if (fout!=stdout) fclose(fout);
|
||||||
if (fin!=stdin) fclose(fin);
|
if (fin!=stdin) fclose(fin);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user