[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: table library changes (was Re: table.new in 5.3?)
- From: "Pierre Chapuis" <catwell@...>
- Date: Wed, 27 Nov 2013 14:43:32 +0100
> On Wed, Nov 27, 2013 at 1:28 PM, John Hind <firstname.lastname@example.org> wrote:
> As has been pointed out, table.insert is slower than t[#t+1], in fact
> it's usually slower than t[#t+1] done in a Lua function, which gives
> you an idea of the cost involved with that C call. (This is good
> news, because t[#t+1] may be better but it really is ugly and hard to
> type). But best of all is just setting t[i] in a loop - nearly 3
> times as fast.
Actually, since the length operator is O(log n) it
can sometimes make sense to maintain an index manually
in a local even when it is not natural in the loop.
See the discussion between Luiz and me on this
Stack Overflow answer: