switch versus if-statements?
#1

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?
Reply
#2

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.
Reply
#3

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.
Reply
#4

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
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)