The performance issue depends on how the compiler creates the jump vector for the case statement.
With an IF-THEN-ELSE statement, you know that execution will proceed checking the first condition, then the second, then the third, and so forth until a match is found, or you run out of statement. Therefore, you can optimize an IF-THEN-ELSE statement, putting the most likely matches at the top of the cascade. For example, consider the following statement:
Code:
If (Color = Red) Then
do something
Else
If (Color = Blue) Then
do something
Else
If Color = Green) Then
do something
End If
End If
End If
If I know that 50% of my colors will be green, 30% will be blue and 20% will be red, then I have coded this if-then-else in the most inefficient and slowest possible manner. If you run your timing tests this way against the comparable case statment you will get one set of results. If you recode the IF-THEN-ELSE statement, changing the order of the checks, you will get a completely different set of results. Therefore without an understanding of both the statement setup and knowledge of the incoming data set, the test results may or may not be misleading, and certainly bring into question their conclusiveness.
Now
Scoty - to fully appreciate the value of results, and to provide some credibility to the results, what was the distribution of the dataset being tested, what was the ordering of the conditions for the ITE statement, and what was the ordering for the case statement for that matter? And perhaps even more important, how clean was the testing environment? In other words, what other tasks the could have consumed processor time were running in the background, while the test was being conducted, thus skewing the results? I am not saying that you're results are incorrect, I just want to be sure that the results are in fact meaningful.
BTW, I will almost always use the case statement when dealing with a set of homogenious conditions.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein