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



Which timer is faster ? - DuyDang2412 - 18.07.2017

Hello guys, I have two timers:
PHP код:
forward Timer1(playerid);
public 
Timer1(playerid)
{
    
SendClientMessage(playerid, -1"...");
}
// Somewhere in the script.
foreach(new iPlayer)
{
    
SetTimerEx("Timer1"1000true"i"i);

__________________________________________
PHP код:
forward Timer1();
public 
Timer1()
{
    foreach(new 
iPlayer)
       {
           
SendClientMessage(playerid, -1"...");
       }
}
// Somewhere in the script.
SetTimer("Timer1"1000true); 
Please help me out of this question, thank you.


Re: Which timer is faster ? - ranme15 - 18.07.2017

The first code will send a message to the whole players ONE time. The second code will keep sending a message very second. Is that what you wished to do?


Re: Which timer is faster ? - Arbico - 18.07.2017

Both are same speed, But the difference is that SetTimerEx comes with parameters meaning you could set player health, send them a message, but the normal SetTimer, will just do what's inside the code, without any parameters, It allows you to make actions for all players, Or the server settings

Rep If I helped


Re: Which timer is faster ? - DuyDang2412 - 18.07.2017

Thank you guys for the answer, it really helped me out! REP+.


Re: Which timer is faster ? - Hansrutger - 18.07.2017

Why aren't you able to set health within the foreach loop? lul

The difference in speed I wouldn't know, test it with benchmarking, but obviously the execution of the first timer will be faster since you are looping in the other. On the other hand you are using a lot of timers on the first one (there is a limit, since the timer index increases for every timer, this you shouldn't worry about but I'm telling you either way so that you will feel an anxiety for writing effective code) and in the long run (again, very long run) the one performing the second timer will be better. Dealers choice.


Re: Which timer is faster ? - Paulice - 18.07.2017

Try to have the less code to execute in a timer as possible, neither one's performance should be a concern to you at this point. Go with what suits best your needs.

If it's just for a message, I'd go with the second one (which in actuality makes no sense because you can just use SendClientMessageToAll as how your code stands).


Re: Which timer is faster ? - DuyDang2412 - 18.07.2017

Thanks a lot for the advice! I will use it in my development!


Re: Which timer is faster ? - aoky - 18.07.2017

Quote:
Originally Posted by Arbico
Посмотреть сообщение
Rep If I helped
lmao