[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Benchmark] Numeric for loop vs. ipairs()
- From: Henk Boom <henk@...>
- Date: Thu, 7 May 2009 01:09:26 -0400
2009/5/6 Javier Guerra <javier@guerrag.com>:
> Duncan Cross wrote:
>> inside the loop - #t is supposed to give you the length of the array
>> part, which is defined as not containing nils anyway.
>
> no.
>
> #t gives you a number such that t[#t]==nil and t[#t-1] ~= nil ; but that could be any such number. if there's holes in the table, #t could be any of the holes, or the 'length' of the array
But there is no v in the second test, it's always nil.
Also, are you trying to benchmark two things which are semantically
equivalent, or two solutions to the same problem? You seem to be doing
the former, while the latter is what's usually useful. If you make the
assumption that there are no holes, you don't need to do the v test in
the second one, and if you assume there may be holes then you would
probably never consider using ipairs.
Henk