This is test.c in view mode; [Download] [Up]
//Modified from Numerical Recipies in C #include <math.h> #import <stdio.h> #import <stdlib.h> #import <sys/time.h> #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr void four1(data,nn,isign) float data[]; int nn,isign; { int n,mmax,m,j,istep,i; double wtemp,wr,wpr,wpi,wi,theta; float tempr,tempi; n=nn << 1; j=1; for (i=1;i<n;i+=2) { if (j > i) { SWAP(data[j],data[i]); SWAP(data[j+1],data[i+1]); } m=n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax=2; while (n > mmax) { istep=2*mmax; theta=6.28318530717959/(isign*mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (m=1;m<mmax;m+=2) { for (i=m;i<=n;i+=istep) { j=i+mmax; tempr=wr*data[j]-wi*data[j+1]; tempi=wr*data[j+1]+wi*data[j]; data[j]=data[i]-tempr; data[j+1]=data[i+1]-tempi; data[i] += tempr; data[i+1] += tempi; } wr=(wtemp=wr)*wpr-wi*wpi+wr; wi=wi*wpr+wtemp*wpi+wi; } mmax=istep; } } #undef SWAP main(){ float qq[5000]; int n,i; double total_time; struct timeval tp1, tp2; struct timezone tzp1, tzp2; for (n=16;n<=1024;n*=2){ gettimeofday(&tp1, &tzp1); // Time the command for(i=0;i<1000;i++){ four1(qq,n,1); } gettimeofday(&tp2, &tzp2); total_time=tp2.tv_sec-tp1.tv_sec+(tp2.tv_usec-tp1.tv_usec)/1000000.0; printf("Total Elapsed time for %d points: %f seconds\n",n, total_time); } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.