Foreach vs GetPlayerPoolSize - 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: Foreach vs GetPlayerPoolSize (
/showthread.php?tid=581727)
Foreach vs GetPlayerPoolSize -
Cineva - 15.07.2015
So all foreach remains the best choice?
[10:28:30] Foreach:141 ms
[10:28:30] Pool:152 ms
[10:28:31] Foreach:140 ms
[10:28:31] Pool:150 ms
[10:28:33] Foreach:143 ms
[10:28:33] Pool:147 ms
[10:28:35] Foreach:136 ms
[10:28:35] Pool:150 ms
Method Testing:
http://pastebin.com/mYWfNLcV
Re: Foreach vs GetPlayerPoolSize -
dominik523 - 15.07.2015
Well, personally, I think foreach is better. Looping through all connected players is better than looping to the top used ID because some of the users might disconnect and I'll just get invalid IDs between 0 and top ID.
Re: Foreach vs GetPlayerPoolSize -
!damo!spiderman - 15.07.2015
Your testing would be fairly inaccurate with little to no people on a server. Use whatever method you feel comfortable with, you won't notice the difference and theres no point trying to preoptimize code
Re: Foreach vs GetPlayerPoolSize -
Vince - 15.07.2015
The test is not entirely correct as foreach only contains connected players; the IsPlayerConnected check should not be there which will make it faster than the PoolSize loop (
with IsPlayerConnected).
Re: Foreach vs GetPlayerPoolSize -
Cineva - 15.07.2015
Yes you are right.
[12:23:12] Foreach:19 ms
[12:23:12] Pool:10 ms
[12:23:14] Foreach:16 ms
[12:23:14] Pool:10 ms
[12:25:19] Foreach:13 ms
[12:25:19] Pool:13 ms
[12:25:20] Foreach:10 ms
[12:25:20] Pool:9 ms
[12:25:20] Foreach:15 ms
[12:25:20] Pool:11 ms
[12:25:21] Foreach:13 ms
[12:25:21] Pool:9 ms