26 C and C++ Source-Level Optimizations Chapter 2
25112 Rev. 3.06 September 2005
Software Optimization Guide for AMD64 Processors
Example 1
A switch statement like this one, whose case expressions are contiguous integer values, usually
provides good performance:
switch (grade)
{
case ‘A’:
...
break;
case ‘B’:
...
break;
case ‘C’:
...
break;
case ‘D’:
...
break;
case ‘F’:
...
break;
}
Example 2
Because the case expressions in the following switch statement are not contiguous values, the
compiler will likely translate the code into a comparison chain instead of a jump table:
switch (a)
{
case 8:
// Sequence for a==8
break;
case 16:
// Sequence for a==16
break;
...
default:
// Default sequence
break;
}