04.04.2010, 18:18
The original question comes to what is better performance-wise: To have one timer which executes a long function every once in a while, or to redistribute the stuff in different timers with different execution times, so they don't run at the same time.
Most likely, distributing the processing in different timers which run at different intervals would be more efficient, since the load would keep the processor in a more constant processing, instead than hitting it hard every now and then.
But now my question is if this would also apply in extreme cases. For example, which of the following two codes would perform better performance-wise?
or:
The second example, would end up running 500 timers at the same time in a full server, and I'm not sure if this would end up being a performance improvement or not against the first example, since it would still need to process the timers' timers.
Most likely, distributing the processing in different timers which run at different intervals would be more efficient, since the load would keep the processor in a more constant processing, instead than hitting it hard every now and then.
But now my question is if this would also apply in extreme cases. For example, which of the following two codes would perform better performance-wise?
pawn Code:
public OnGameModeInit()
{
SetTimer("LoopFunction", 2500, 1);
return 1;
}
forward LoopFunction();
public LoopFunction()
{
for(new i; i < MAX_PLAYERS; i ++) if(IsPlayerConnected(i))
DoStuffWithPlayer(i);
}
pawn Code:
new Timers[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
Timers[playerid] = SetTimerEx("DoStuffWithPlayer", 2500, 1, "i", playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(Timers[playerid]);
return 1;
}