lua-users home
lua-l archive

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


What if the array portion of a table had space to hold "n"?

Mark

on 11/4/04 4:25 AM, Steve Donovan at sjdonova@csir.co.za wrote:

>>>> sjdonova@csir.co.za 11/04/04 02:08PM >>>
>> Looking at the implementation of table.insert, this may not be
>> optimal, but I don't think tbl[kk] = val;  kk = kk + 1 is
>> going to be much faster
> 
> Hm, always a good idea to run tests before giving an
> opinion!
> 
> -- adding by index
> local tbl = {}
> local k = 1
> for i = 1,1000000 do
>   tbl[k] = i
>   k = k + 1
> end
> 
> -- using append
> local append = table.insert
> local tbl = {}
> for i = 1,1000000 do
>  append(tbl,i)
> end
> 
> Well, the first snippet is about four times as fast!
> 
> steve d.
> 
>