I Created a Look_up table class but when I test it with sin() and cos() it is actually slower than stdlib math's sin. This surprises me by a lot.
inline double MATH_TABLES::GetSind(double& value)
{
return mp_Sind[(static_cast<int>(value/m_SinPrecisiond)];
}
mp_Sind is simply an array of doubles. This is the non-Lerp'd version and it is even slower than by an average of 1.5-2x than sin(x). I am quite surprised by this. Is there something in this code that stands out as a reason for it a table lookup being slower than a sin() function?
Test Code
const unsigned int NUMSINS = 100000;
double Sins[NUMSINS];
boost::timer Timer;
MATH_TABLES Sind;
void TestSinChart()
{
int counter = 0;
double time_table = 0;
double time_reference = 0;
Timer.restart();
while( NUMSINS > counter++)
{
Sind.GetSind(Sins[counter]);
}
time_table = Timer.elapsed();
counter = 0;
Timer.restart();
while(NUMSINS > counter++)
{
sin(Sins[counter]);
}
time_reference = Timer.elapsed();
std::cout << "Num Tests: " << counter-1 << "\n";
std::cout << "Table Time: " << time_table*1000 << " ms \n";
std::cout << "Reference Time: " << time_reference*1000 << " ms\n";
}