lua-users home
lua-l archive

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


On Thu, Aug 13, 2009 at 6:09 PM, Peter Cawley<lua@corsix.org> wrote:
> Should now be fixed.

Patch applied fine, then built with MS cl compiler.  None of my code
falling over so far.

The {unpack(t1)...,unpack(t2)} idiom is a good deal faster than the
manual method of creating a table which is the concatenation of t1 and
t2.

For t1 and t2 both having 3 elements, then this method takes 1.6 vs 3.5 sec;

For t1 and t2 having 10 elements, then we get 2.4 vs 7.2 sec.

It's possible that someone might be able to squeeze a little extra bit
of speed out of the normal code (pulling in an explicit table size
setter would probably help) so here is the unscientific code behind
the numbers:

steve d.

-----
N = 1e6

function concatn1 (t1,t2)
    for K = 1,N do
        local t = {}
        for i = 1,#t1 do
            t[i] = t1[i]
        end
        local k = #t1 + 1
        for i = 1,#t2 do
            t[k] = t2[i]
            k = k + 1
        end
    end
end

function concatn2 (t1,t2)
    for K = 1,N do
        local t = {unpack(t1)...,unpack(t2)}
    end
end


t1 = {10,20,30,1,2,3,11,12,13,14}
t2 = {40,50,60,4,5,6,41,51,61,62}

t = os.clock()
concatn1(t1,t2)
print('elapsed',os.clock()-t)

t = os.clock()
concatn2(t1,t2)
print('elapsed',os.clock()-t)