lua-users home
lua-l archive

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


>>> 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.



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
MailScanner thanks transtec Computers for their support.