lua-users home
lua-l archive

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


25% can be significant in some applications. Anyway,
I'd prefer the "t[] = value" notation for brevity and
clarity.

--- Javier Guerra <javier@guerrag.com> wrote:

> On Monday 11 September 2006 1:03 pm, Tim Gogolin
> wrote:
> > Right; I understand this point of view.  The
> problem though is that
> > table.insert(t, v ) has a hash lookup penalty and
> a function call
> > penalty.
> >
> > local table_insert = table.insert
> >
> > will get rid of the hash lookup, but the function
> call is somewhat
> > painful inside a tight loop.
> 
> on my machine (2.4Ghz P4, 512KB, kubuntu Dapper,
> lua5.1):
> 
> time lua -e 'local t={} for i = 1,1e7 do t[#t+1]=1
> end'
> real    0m4.730s
> user    0m4.136s
> sys     0m0.480s
> 
> time lua -e 'local t={} local tinsert=table.insert
> for i = 1,1e7 do tinsert 
> (t,1) end'
> real    0m5.884s
> user    0m5.100s
> sys     0m0.476s
> 
> less than 25% difference... not significant
> 
> -- 
> Javier
>