File: fftTiming.c

package info (click to toggle)
audacity 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 86,844 kB
  • sloc: ansic: 225,005; cpp: 221,240; sh: 27,327; python: 16,896; makefile: 8,186; lisp: 8,002; perl: 317; xml: 307; sed: 16
file content (98 lines) | stat: -rw-r--r-- 2,143 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*  A program to time complex forward and inverse fast fourier transform routines	*/
void four1(float data[], unsigned long nn, int isign);

#include <stdio.h>
#include <stdlib.h>
#include <fp.h>
#include <math.h>
#include "fftlib.h"
#include "fftext.h"

#if macintosh
#include <timer.h>
#endif

#define NSIZES 3		/* the number of different ffts sizes to time */

typedef  struct{
	float Re;
	float Im;
	} Complex;

void main(){
long 	fftSize[NSIZES] = {1024, 16384, 262144};	/* size of FFTs, must be powers of 2 */
long 	fftRepeats[NSIZES] = {2000, 50, 1};		/* number of timing loops */
Complex	*a;
long 	isize;
long 	i1;
long 	TheErr;
long	N;
long	M;

#if macintosh
UnsignedWide 		TheTime1;
UnsignedWide 		TheTime2;
double		TheTime;
#endif

printf(" %6d  Byte Floats \n", sizeof(a[0].Re));
for (isize = 0; isize < NSIZES; isize++){

	N = fftSize[isize];
	printf("ffts size = %7d,  ", N);
	M = roundtol(LOG2(N));

	TheErr = fftInit(M);

	if(!TheErr){
		a = (Complex *) malloc(N*sizeof(Complex) );
		if (a == 0) TheErr = 2;
	}

	if(!TheErr){

			/*  set up a simple test case */
		for (i1=0; i1<N; i1++){
			a[i1].Re = sqrt(i1+.77777);
			a[i1].Im = sqrt(i1+.22222);	
		}

	#if macintosh
							/* make sure routines are in physical (not virtual) memory */
		Microseconds(&TheTime1);
		ffts((float *)a, M, 1);
		iffts((float *)a, M, 1);

		Microseconds(&TheTime1);

		for (i1=0;i1<fftRepeats[isize];i1++){		/* do many times for timing */
			ffts((float *)a, M, 1);
			iffts((float *)a, M, 1);
		}	

		Microseconds(&TheTime2);

		TheTime = (double)(TheTime2.hi - TheTime1.hi) * 65536.0 * 65536.0;
		TheTime = (TheTime + (double)(TheTime2.lo - TheTime1.lo));
		printf("ffts time = %12.1f  s,  a[0].Re=%6e\n", TheTime/fftRepeats[isize]/2, a[0].Re);

	#else
		printf("start timing %12d real ffts's\n", fftRepeats[isize]*2);
		for (i1=0;i1<fftRepeats[isize];i1++){		/* do many times for timing */
			ffts((float *)a, M, 1);
			iffts((float *)a, M, 1);
		}
		printf("end timing \n");
	#endif
		free(a);
		fftFree();
	}
	else{
		if(TheErr==2)	printf(" out of memory \n");
		else	printf(" error \n");
		fftFree();
	}
}
printf(" Done. \n");
return;
}