Ipairs

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Ipairs

Post by LuaWeaver »

Thank you, that explains quite a bit.
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Ipairs

Post 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.
User avatar
pudding
Prole
Posts: 6
Joined: Tue Jul 05, 2011 5:09 am
Location: Paris, France

Re: Ipairs

Post by pudding »

Here's a link to the exciting graphs: http://www.facepunch.com/threads/875909 ... and-ipairs
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Ipairs

Post 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)
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Ipairs

Post 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
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Ipairs

Post 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.
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Ipairs

Post 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.
Help us help you: attach a .love.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Ipairs

Post 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
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests