[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "clear" array
- From: Glenn Maynard <glenn@...>
- Date: Thu, 28 Sep 2006 23:00:23 -0400
On Fri, Sep 29, 2006 at 12:52:42PM +1000, Nick Gammon wrote:
> This has the advantage that if you have other references to the table
> (you may not) then they all point to the same, emptied, table. Also,
> for small tables it may be faster than creating a new table. For
> larger tables, and if you don't have references to the table
> anywhere, making a new one is probably faster.
# echo 'for i = 1,1000000 do local a = { 5, 6, 7, 8, 8 }; a = {}; end' | time lua -
1.75user 0.00system 0:01.76elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
# echo 'for i = 1,1000000 do local a = { 5, 6, 7, 8, 8 }; for k in pairs(a) do a[k] = nil; end; end' | time lua -
4.98user 0.00system 0:05.00elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
It's hard to imagine the latter being faster. It's slower even with
even just one element.
For a baseline:
# echo 'for i = 1,1000000 do local a = { 5, 6, 7, 8, 8 }; end' | time lua -
1.19user 0.00system 0:01.20elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
--
Glenn Maynard