⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_speedfft.cpp

📁 几个FFT算法
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

extern "C" double currTime();

extern "C" void cdft(int n, int isgn, double *a);

void  initTestData(double  data[],int len)
{
	/*  pre code
	int i;

	for (i=0;i<len;i++)
	{
		data[2*i]=(double)(rand() % 1000);
		data[2*i+1]=(double)(rand() % 1000);
	}
	*/

	//add by tonnyue

	memset(data, len, sizeof(double));

	srand( (unsigned)time( NULL ) );
	data[rand()%1000]=1;
	data[rand()%1000]=1;
	data[rand()%1000]=1;


	//end add

}

void testSpeed_oouraFFT(int maxLen)
{
	int  len,c;
	double k,t,tmp;
	double *data=NULL;
	FILE *fp=fopen("benchmark.txt","wt");
	if (fp==NULL)
		return;

	data=new double[maxLen*2];
	if (data==NULL)
		return ;

	t=currTime();
	fprintf(fp,"    len  \tfft time \ttime/(n*log2(n)\n");
	
	for (len=64;len<=maxLen;len*=2)
	{
		t=0.0;
		c=0;
		
		initTestData(data,len);
		
		while (true)
		{
			tmp=currTime();
			cdft(len*2,-1,data);		
			t+=currTime()-tmp;
			
			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);
	if (data!=NULL)
		delete[] data;

}

int main()
{
	testSpeed_oouraFFT(2*1048576);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -