Loops?
#1

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

Good idea, must test it too,
Reply
#3

Looking forward to hearing from any one else
Reply
#4

And how many players did you have on the server during testing?
Reply
#5

well every millisecond counts, i'll try it to some time
Reply
#6

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)