lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, May 6, 2009 at 10:14 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> Hi, list!
>
> Continuing my micro-benchmarking series.
>
> Today I'm benchmarking iterating a table with ipairs vs. numeric for:
>
> local do_loop_ipairs = function(t)
>   for i, v in ipairs(t) do
>   end
> end
>
> local do_loop_numfor = function(t)
>   do_nothing() -- Compensating for ipairs() call
>   for i = 1, #t do
>     if v == nil then
>       break
>     end
>   end
> end

I admit that I don't know that much about benchmarking, but I don't
see why you would compensate for the ipairs call - why is that not
considered part of what you are measuring?

I also also don't really understand why you are testing v for nil
inside the loop - #t is supposed to give you the length of the array
part, which is defined as not containing nils anyway.

-Duncan