The future of computer architecture will use lookup tables. Currently
computer processor speed outweighs the benefits of using computer
memory for lookup tables, except in some cases. As computer memory
increases, new ROM chips will be built with lookup tables hardcoded
into them. Here is an example of what using a lookup table can do for
you. The following program divides to integers from 0 to 4 using
lookup tables and times itself against the same operation using the
division operator in c++.
I came up with this idea myself, and met critisism everywhere I brought
it up. It is actually a handy algorithm and you can read more about it
on wikipedia:
http://en.wikipedia.org/wiki/Lookup_table
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main(int argc, char *argv[]){
time_t t1, t0;
double elapsed;
float div[5][5]={ {0,0,0,0,0}, {1,0.5,0.3333,0.25,0.2},
{2,1,0.6666,0.5,0.4}, {3,1.5,1,0.75,0.6}, {4,2,1.3333,1,0.8} };
int a=1, b=2;
float ans=0;
time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){
ans=div[a][b];
}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed<<" seconds."<<endl;
time(&t0); /* start time */
for(int cnt=0; cnt<1000000000; cnt++){
ans=a/b;
}
time(&t1);
elapsed = difftime(t1, t0);
cout<<"Time: "<<elapsed<<" seconds."<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}