[Mono-list] [Off-topic] "if else" or "switch" ?
Fabien Meghazi
agr@amigrave.com
Fri, 15 Oct 2004 16:35:04 +0200
Hi all,
I was wondering if mono would generate diferent code between a "switch"
and an "if else suite". I guess yes.
But I would like to know wich of the two code would be faster ?
(I know we are speaking of a few cpu cycles of difference, but I would like to
know anyway) I would have benchmark this but I've nothing to do this, and I
guess that this question could be theorically answered easily by those how
put their hand in mono compiler.
So which of those two methods generate faster code ?
PS: orientation is a string and the following code is in a for loop :
// --> for (int i = 0; i < orientation.Length; i++)
Method 1
*************************************
switch (orientation[i]) {
case 'l':
left = true;
break;
case 'r':
left = false;
break;
case 't':
top = true;
break;
case 'b':
top = false;
//break;
}
Method 2
*************************************
char or = orientation[i];
if (or == 'l') left = true;
else if (or == 'r') left = false;
else if (or == 't') top = true;
else if (or == 'b') top = false;
--
Fabien Meghazi
http://www.amigrave.com