lua-users home
lua-l archive

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


> Date: Mon, 25 Nov 2013 22:52:35 -0500
> From: Sean Conner <sean@conman.org>
> Subject: Re: table library changes (was Re: table.new in 5.3?)
>
> > >   I actually went to the trouble to measure the code and indeed, the
> > > "optimized" version does indeed run faster (about 10x), *BUT* it
> > > does *NOT* produce identical results.
> > >> > >   I realize you were trying to prove a point here, but it might be
> > > made a bit better if both code fragments actually did identical work.
> >
> > What's the difference?
>
> The size of the resulting arrays (original: 9909 "optimized": 9899) and
> 90 incorrect values:
>
> index	orig	optmized
> -------------------------
> 10      11      10
> 11      13      102

Good point, well made! Like Galileo, seeing that the answer was obvious from the thought experiment, I did not bother doing the actual experiment. But debug the code and the answer will be the same. Note that the 10x improvement comes from the number of elements removed - remove 1001 elements and it will be (close to) 1000x better!

My screw-up does show that ad-hoc coding this kind of thing is error prone. So it would be worth having multi-element insert and remove in a library, but a Lua library please, not 'C'.  As they say (but do not do) at Yahoo, we should "eat our own dog food"!



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com