?? test_speedfft.cpp
字號:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
extern "C" double currTime();
extern "C" void fft(int n, double xRe[], double xIm[],
double yRe[], double yIm[]);
void initTestData(double xRe[],double xIm[],int len)
{
int i;
for (i=0;i<len;i++)
{
xRe[i]=(double)(rand() % 1000);
xIm[i]=(double)(rand() % 1000);
}
}
void testSpeed_fft(int maxLen)
{
int len,c;
double *xRe= new double[maxLen];
double *xIm= new double[maxLen];
double *yRe= new double[maxLen];
double *yIm= new double[maxLen];
FILE *fp;
double k,t,tmp1,end;
if (yRe==NULL || yIm==NULL)
{
printf("No enough memory to alloc\n");
}
fp=fopen("benchmark.txt","wt");
if (fp==NULL)
return;
fprintf(fp," len \tfft time \ttime/(n*log2(n)\n");
for (len=64;len<=maxLen;len*=2)
{
t=0.0;
c=0;
initTestData(xRe,xIm,len);
while (true)
{
tmp1=currTime();
fft(len,xRe,xIm,yRe,yIm);
t+=currTime()-tmp1;
c++;
if (t>0.001)
break;
}
t/=c;
k=t/(len*log10(len)/log10(2));
fprintf(fp,"%8d \t%.8f \t%.12f\n",len,t,k);
}
fclose(fp);
delete[] xRe;
delete[] xIm;
delete[] yRe;
delete[] yIm;
}
int main()
{
testSpeed_fft(2*1048576);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -