I working on a hexgrid program and need to test if an angle is
- less than 30 degrees
- equal to 30 degrees
- between 30 and 60 degrees
- equal to 60 degrees
- greater than 60 degrees
I have
public int TestA(double angle)
{
if(angle<=30)
{
if(angle==30)
return ANGLE_EQUALS_30;
else
return ANGLE_LESS_THAN_30;
}
if(angle>=60)
{
if(angle==60)
return ANGLE_EQUALS_60;
else
return ANGLE_GREATER_THAN_60;
}
return ANGLE_BETWEEN_30_AND_60;
}
but of course I could have
public int TestB(double angle)
{
if(angle<30) return ANGLE_LESS_THAN_30;
if(angle==30) return ANGLE_EQUALS_30;
if(angle<60) return ANGLE_BETWEEN_30_AND_60;
if(angle==60) return ANGLE_EQUALS_60;
return ANGLE_GREATER_THAN_60;
}
Is TESTA really quicker than TESTB? Or does the compiler end up spliting an <= test into 2 tests (< and ==), so TESTA is actually performing more tests then TESTB?
I would just write a program to test it, but I have a feeling that it's going to be so close that programs running in the background will make more of a difference.