Which timer is faster ?
#1

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

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?
Reply
#3

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)