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

📄 test_fft.cpp

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

extern "C" double currTime();

void four1(double data[], int nn, int isign);

void  initTestData(double data[],int len)
{
	int i;
	for (i=1;i<=len*2;i+=2)	//base 1
	{
		data[i]=(double)(rand() % 1000);
		data[i+1]=(double)(rand() % 1000);
	}
}

void testSpeed_fft(int maxLen)
{
	int len,c;
	double *data = new double[maxLen*2+2];
	FILE *fp;
	double k,t,tmp1;
	if (data==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(data,len);
		
		while (true)
		{
			tmp1=currTime();

			four1(data, len, 1);
			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[] data;
}

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

⌨️ 快捷键说明

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