switch versus if-statements? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: switch versus if-statements? (
/showthread.php?tid=181799)
switch versus if-statements? -
LarzI - 07.10.2010
What is really the fastest and most efficient?
I'm familiar with using switches when checking IDs, for an example:
pawn Код:
switch(vehicleid)
{
case 0: //blah
case 1..32: //more blah
}
But is that faster than just doing
pawn Код:
if(vehicleid == 0)
{ /*blah*/ }
else if(vehicleid > 0 && vehicleid < 33)
{ /*more blah*/ }
... or is it just shorter?
Re: switch versus if-statements? -
Harry_Gaill - 07.10.2010
From previous memories I recall in PAWN there is no difference between the 2 (at low level). It only matters in languages like C, C++ etc... Correct me if I'm mistaken though.
Re: switch versus if-statements? -
jameskmonger - 07.10.2010
With one or two in each, it makes no difference. Although 1000 cases in a switch statement is more efficient than 1000 if-else-statements.
Re: switch versus if-statements? - Zeex - 07.10.2010
speed? you better should worry about your algorithms' efficiency rather than about such little unimportant things which don't really affect the total speed of your code anyway, so fuck it and use what you like more
Re: switch versus if-statements? -
LarzI - 07.10.2010
Quote:
Originally Posted by jameskmonger
With one or two in each, it makes no difference. Although 1000 cases in a switch statement is more efficient than 1000 if-else-statements.
|
It was just an example, I meant in larger cases of course.
Quote:
Originally Posted by Harry_Gaill
From previous memories I recall in PAWN there is no difference between the 2 (at low level). It only matters in languages like C, C++ etc... Correct me if I'm mistaken though.
|
Hmm, ok.
Quote:
Originally Posted by Zeex
speed? you better should worry about your algorithms' efficiency rather than about such little unimportant things which don't really affect the total speed of your code anyway, so fuck it and use what you like more
|
Quote:
Originally Posted by Myself
What is really the fastest and most efficient?
|
I was just wondering, 'cause I want to optimise my code as much as possible.