Loops? - 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: Loops? (
/showthread.php?tid=176813)
Loops? -
wups - 14.09.2010
I was just thinking, would a value checking be faster than
pawn Code:
IsPlayerConnected(playerid)
like
pawn Code:
public OnPlayerConnect(playerid) connected[playerid]=true;
public OnPlayerDisconnect(playerid) connected[playerid]=false;
for(new i; i< MAX_PLAYERS;i++)
{
if(connected[playerid])
{
// do sth here.
}
}
I did a quick test with code
pawn Code:
new time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
foreach(Player,I)
{
item1[I][i]=100;
}
}
printf("Time #1: %d", GetTickCount() - time);
time = GetTickCount();
for (new i = 0; i < 10000; i++)
{
for(new I=0;I<100;I++) { if(connected[I])
{
item3[I][i]=300;
} }
}
printf("Time #3: %d", GetTickCount() - time);
Foreach was 104 msec, and mine was 41 msec.
Re: Loops? -
Voldemort - 14.09.2010
Good idea, must test it too,
Re: Loops? -
wups - 15.09.2010
Looking forward to hearing from any one else
Re: Loops? - Zeex - 15.09.2010
And how many players did you have on the server during testing?
Re: Loops? -
ExoSanty - 15.09.2010
well every millisecond counts, i'll try it to some time
Re: Loops? -
Hiddos - 15.09.2010
Yerp, I mentioned this as well in a few tests I did some time ago. And I guess that using " if(!connected[i]) continue " is kinda slow as well.
Re: Loops? -
wups - 15.09.2010
Oh yes, i tested it again and it was like 200x slower. Sorry, my bad, maybe my computer lagged yesterday, because i only checked one result