lua-users home
lua-l archive

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


"Aaron Brown" <arundelo@hotmail.com> writes:

> Roberto wrote:
>
>> (I am not claiming this is useful for any particular task;
>> I am only showing that not creating a new closure is not
>> an optimization: it changes the semantics of the
>> language.)
>
> Do-nothing functions can be used as gensyms (unique values).
> They are a slightly faster to create than empty tables:
>
> $ time lua -e 't={} for i=1,999999 do t[i]={}end'
>
> real    0m5.453s
> user    0m5.249s
> sys     0m0.124s
> $ time lua -e 't={} for i=1,999999 do t[i]=function()end end'
>
> real    0m3.172s
> user    0m2.890s
> sys     0m0.170s

The question is whether this use should be recommended.  At some point
of time, one takes away all possibilities for optimizing code if one
declares every existing behavior as useful.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum