A
Andrew Tomazos
Please consider the following code...
void on_equal_to();
void on_less_than();
void on_greater_than();
enum EComparisonResult
{
eEqualTo,
eLessThan,
eGreaterThan
};
inline EComparisonResult CompareIntegers(int a, int b)
{
if (a == b)
return eEqualTo;
else if (a < b)
return eLessThan;
else
return eGreaterThan;
}
void f1(int a, int b)
{
switch (CompareIntegers(a,b))
{
case eEqualTo: on_equal_to(); return;
case eLessThan: on_less_than(); return;
case eGreaterThan: on_greater_than(); return;
}
}
void f2(int a, int b)
{
if (a == b)
on_equal_to();
else if (a < b)
on_less_than();
else
on_greater_than();
}
Would you expect that the optimizer will produce code for f1 that has
equal performance to f2? Why or why not?
Thanks,
Andrew.
void on_equal_to();
void on_less_than();
void on_greater_than();
enum EComparisonResult
{
eEqualTo,
eLessThan,
eGreaterThan
};
inline EComparisonResult CompareIntegers(int a, int b)
{
if (a == b)
return eEqualTo;
else if (a < b)
return eLessThan;
else
return eGreaterThan;
}
void f1(int a, int b)
{
switch (CompareIntegers(a,b))
{
case eEqualTo: on_equal_to(); return;
case eLessThan: on_less_than(); return;
case eGreaterThan: on_greater_than(); return;
}
}
void f2(int a, int b)
{
if (a == b)
on_equal_to();
else if (a < b)
on_less_than();
else
on_greater_than();
}
Would you expect that the optimizer will produce code for f1 that has
equal performance to f2? Why or why not?
Thanks,
Andrew.