/**
 * This program will compare the efficiency of calculating values
 * through a function or a look-up table
 */

#include <stdlib.h>
#include <time.h>

#define A 76.5
#define B 14.8

#define ITERATIONS 100000000


float psd_function(int x)
{
	return B/(x-A);	
}


int main()
{
	time_t start,end;
	float T[256],y;
	int i,x;

	// Create the lookup table	
	for(i=0;i<256;i++)
	       T[i] = psd_function(i);

	
	// Simulate for function
	start = time(NULL);
	for(i=0;i<ITERATIONS;i++)
	{
		x = rand()%256;
		y = psd_function(x);
	}
	end = time(NULL);

	printf("Function calls took %f seconds.\n",difftime(end,start));
		
	
	// Simulate for look-up table
	start = time(NULL);
	for(i=0;i<ITERATIONS;i++)
	{
		x = rand()%256;
		y = T[x];
	}
	end = time(NULL);
	
	printf("Look-up calls took %f seconds.\n",difftime(end,start));
	
	return 0;	
}
