SA-MP Forums Archive
Which is faster? - 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)
+--- Thread: Which is faster? (/showthread.php?tid=522171)



Which is faster? - Battlezone - 26.06.2014

I got:

pawn Код:
#define JOHN    0
#define DOG     1
#define DRAKE   2
#define MILEY   3
then i make a stock like this one (uhh its just an example)

pawn Код:
stock MakePlayerDance(playerid)
{
    //
}
now under OnPlayerSpawn , I want to make all of them dance, so i got 2 solutions, either i make a loop or i just use switch statements

1-
pawn Код:
for(new i = 0; i < 4; ++i)  MakePlayerDance(i);
or 2-

pawn Код:
switch(playerid)
{
      case JOHN:
}
which is faster / less memory using ( btw in my real script i got over 36 case)
(+ please don't tell me you could use foreach, in my real script its not about players, i jus didnt find a good example)


Re: Which is faster? - Battlezone - 26.06.2014

wow! this reached the 3rd page in almost 2 hours! bump


Re: Which is faster? - RedFusion - 26.06.2014

Why don't you check for yourself? You can check the time your code takes to execute with GetTickCount. I don't think the difference is noticeable at all though, but i bet the switch is the fastest


Re: Which is faster? - Battlezone - 26.06.2014

okey, one more question, is this the same thing (in speed/performance)?
pawn Код:
for(new i = 0; i < 4; ++i)  MakePlayerDance(i);
as
pawn Код:
MakePlayerDance(0);
MakePlayerDance(1);
MakePlayerDance(2);
MakePlayerDance(3);



Re: Which is faster? - Battlezone - 26.06.2014

Great, thanks!