Just want to know to optimize some of my scripts.
✓ ANSWER ACCEPTED
What's better: a standard "for" loop or a "in pairs" loop?
1 answer
✓ Accepted answer
They both are good. Numeric for loops are slightly faster because they don't use function calls. Pairs uses function calls. Pairs is essentially this:
function pairs(x)
return next,x,nil
end
So when the loop runs, it keeps calling that function thus making it slightly slower. HOWEVER you won't notice much of a difference unless a table has millions of elements inside of it.
This discussion is preserved as it was. New answers, comments, and votes are closed.
