Page 2 of 2

Re: Ipairs

Posted: Tue Aug 09, 2011 4:21 pm
by LuaWeaver
Thank you, that explains quite a bit.

Re: Ipairs

Posted: Tue Aug 09, 2011 6:58 pm
by Kadoba
T-Bone wrote: Are these two methods equally fast by the way?
Using pairs is slightly faster than ipairs. Indexing is quite a bit faster than both. There was a discussion over this recently with a nice graph illustrating the speeds of the different iterating methods, but I can't find the thread now.

Re: Ipairs

Posted: Tue Aug 09, 2011 7:24 pm
by pudding
Here's a link to the exciting graphs: http://www.facepunch.com/threads/875909 ... and-ipairs

Re: Ipairs

Posted: Tue Aug 09, 2011 10:27 pm
by thelinx
Also, "arrays", or tables that are number-ordered like {"item", "another item", "you get the idea"} are called "sequences" in Lua. (according to the Lua 5.2 documentation)

Re: Ipairs

Posted: Wed Aug 10, 2011 4:18 pm
by Xgoff
pudding wrote:Here's a link to the exciting graphs: http://www.facepunch.com/threads/875909 ... and-ipairs
... wait, there were arguments over which of pairs or ipairs were faster? what? this shouldn't be an issue in the first place since they aren't really interchangeable to begin with

the only one i remember hearing about is ipairs vs a numeric for, the latter of which is faster mainly because it doesn't have a per-iteration function call

Re: Ipairs

Posted: Wed Aug 10, 2011 4:24 pm
by kikito
Kadoba wrote:Using pairs is slightly faster than ipairs.
The article pointed out by pudding states that pairs is faster under very specific circumstances - tables with more than 15k elements. That's the edge case, not the norm; you usually have less than that. Ipairs is the fastest one in general.

Re: Ipairs

Posted: Wed Aug 10, 2011 9:00 pm
by Robin
Still, why would you care either way? They do what they're supposed to do, and they're still much faster than anything in, say, Ruby.

This is not meant as a slight against Ruby: it usually also gets the job done, in terms of speed.

Re: Ipairs

Posted: Wed Aug 10, 2011 10:17 pm
by kikito
you are absolutely right. Most of the time, these small differences don't matter.

Nevertheless, I was curious about the situation: it isn't intuitive that pairs is faster, even if only in some cases