[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Changes to iterators in 4.1-work4
- From: Edgar Toernig <froese@...>
- Date: Sun, 17 Feb 2002 17:15:24 +0100
Tom Wrensch wrote:
> In short his feature is seriously cool.
Calm down ;-) Sure, it's nice. But it's not for free - it's
pretty heavy weight. Because the for-statement does not manage
any state for the iterator one has to create a closure each time.
I.e. your indexiter creates three (short living) GC'ed objects.
And the function call costs too. Something one should realize
when using this feature.
Some numbers about the loop overhead:
return function() i=i+1 return t[i] end
for i=1,1000000 do
--for j=1,getn(t) do local j=t[j] end -- Lua: 12.0s
--for j in iter(t) do end -- Lua: 28.2s (includes ~4900 gc cycles!)
--for j=1,t:getn() do local j=t[j] end -- Sol: 10.8s (dispite old vm?!?)
--for j over t do end -- Sol: 4.1s