#ipairs vs pairs vs none

1 messages · Page 1 of 1 (latest)

green ledge
#

Like when this situation, ```
local plr = game.Players:GetPlayers()



what should i use and what’s best for performance?

for i, v in ipairs(plr) do

or

for i, v in pairs(plr) do

or

for i, v in plr do
hardy hazel
#

this was posted awhile back

#

the generalized version (the last one) is fastest

#

ipairs is second best for this purpose

#

and pairs is slowest, but allows you to get keys from dictionaries

hardy hazel
#

no

#

in a basic loop yes

#

but actually the time it takes to index the table and do anything with it will slow it down slower than ipairs

#

its weird but functionally it is faster as a loop until you do anything inside the loop with it

hardy hazel
#

its a common misconception

#

the benchmark will return true until you try to do something with the number

#

so for non-table loops

#

yes its faster

#

try with a more practical example

#

ive run into this many times and I've also made the claim the guy made before

#

and i was wrong

hardy hazel
#

that's not the issue

#

the value of the number was never the problem