SetTimerEx or SetTimer+foreach ?
#1

hey ya!

Ok i have a question, a performance question.


Its better use

(all codes here its just examples)

pawn Код:
public OnPlayerConnect(playerid)
{
    playertimer[playerid] = SetTimerEx("GiveCookie",500,true,"i",playerid);
    return 1;
}

public GiveCookie(playerid)
{
    CookieStatus[playerid][cookieamount]++;
}
Or

pawn Код:
public OnGameModeInit()
{
    SetTimerEx("GiveCookie",500,true);
    return 1;
}

public GiveCookie()
{
    foreach(new i : Player) {
        CookieStatus[i][cookieamount]++;
    }
}

?
Reply
#2

In my opinion using foreach is more efficient than SetTimerEx .
Reply
#3

foreach too with large amount of var set? or large checks?
Reply
#4

I don't understand what you meant to say ...
Reply
#5

I have no clue, but I would say the foreach as that's just one timer and not 500 (or how many people on the server) timers.

But as I said, I don't really know.
Reply
#6

Using the foreach case and not setting just a cookie var but like 70 vars?
Reply
#7

I'd go with the second option it's better suited since you can leave out the overhead of Setting and Killing timers.
Reply
#8

So the second option is better in performance?
Reply
#9

I don't know exactly how timers in SA-MP work, but here's a likely theory:

In the server's main 'timer', all timers are looped through to see whether they are needed to be called. This means, if you have a lot of timers, it's looping through a LOT more timers to check whether they need to be called. It's also possible that expired timers are also checked, which means using a timer for every player is likely less efficient.

I think ****** said something regarding this once.
Reply
#10

Quote:
Originally Posted by iJumbo
Посмотреть сообщение
So the second option is better in performance?
Definitely, no need to SetTimer on connect or KillTimer on disconnect which saves some function calls but I think what MP2 has to say is most likely along the lines of why lots of timers are poor performance wise.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)