Foreach vs GetPlayerPoolSize
#1

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

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

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)