Efficiency of timers - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Efficiency of timers (
/showthread.php?tid=228712)
Efficiency of timers -
!Phoenix! - 20.02.2011
Hey all,
While writing a script it's important for me to make it as efficient as I can do it.
So I taught about what would be better:
For example(!), I have a timer which repeats every second and checks for cheats. Furthermore the players speed (in vehicle) should be updated every second (speedometer) and a clock every 60 seconds.
So we have two functions which runs all the time (cheat-detector and clock-updater) and one which actually only have to run if the player is in a vehicle. Cheat-Detector and speedometer with the same interval and the clock * 60
What would be the best way to do it?
1. A seperate timer for each function (and each player who enters a vehicle)
2. Speedometer together with cheatfunction (for -> if in vehicle)
3. All together (2. + if sec == 60 do min++)
I don't exactly know how timers work so I ask for your knowledge
Phoenix
Re: Efficiency of timers -
iggy1 - 20.02.2011
I'd use seperate timers and stagger them. Its not timers that are inefficient its what people put inside them that is. You should set the players speedo timer when they enter a vehicle with SetTimerEx.
AW: Efficiency of timers -
!Phoenix! - 20.02.2011
Do timers anyway need computing power while they are not running? (Something like the server checks every second if a task has to be executed either way)
Re: Efficiency of timers -
iggy1 - 20.02.2011
I'm not sure how it works internally but, generally a CPU can process many "ifs" per millisecond (depending on what it is checking ofc) so i can't see it being inefficient. I'm no expert on efficiency But thats what i gather. In a mode i'm writting every player has their own update timer, so i don't have to use one timer that loops through all players saving their stats. (maybe causing lag spikes)
AW: Efficiency of timers -
!Phoenix! - 20.02.2011
Ok, thanks a lot, iggy1
(If anyone knows exactly how it works I would be still interested
![Smiley](images/smilies/smile.png)
)
Re: Efficiency of timers -
Macluawn - 20.02.2011
If you have a lot of code inside them then you should keep them separate. But if its only few lines in timers that collide, you should combine them.
AW: Efficiency of timers -
!Phoenix! - 20.02.2011
Thanks but now I'm not really smarter.
WHY?
(So only one user-unspecific timer for a speedometer?)