lua-users home
lua-l archive

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


Hello!

An "ridiculous" evaluation of the Levenshtein distance in pure Lua:
http://gist.github.com/158506/
I took no care in the "quality" of this code, so you might want to
tear your eyes out.
I'd be very interested in performance tweaks/code reduction, from
minor remarks to global rewrites, as long as it remains pure Lua with
standard libraries. I didn't think a lot about it, specially the use
of table.sort which must be stupid.
I used this dictionary: http://koon.fr/~gcarrier/web2 (from NetBSD).
You can deduce from the commented block that I first intended to
"build the whole map of words by proximity" (whatever that would have
meant by the time I got there). But with computations taking up to
dozens of seconds per word...

Anyway, if someone wants to play on a clever and/or efficient way to
do something around a dictionary, I'd be interested too!

Something a little older now...

Try to guess what this does (warning!! answer and thoughts below):
guess = function(a,b) return a==0 and b or b==0 and a or a>b and
guess(a-b,b) or guess(a,b-a) end

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

These are dumb implementations of the Euclidean algorithm:
http://gist.github.com/151987

Sometimes white spaces might help :)

I'm looking for a precise analysis of the small time difference (5%).
My current guess:
- Tails call optimization in guess2(), not guess()
- guess() checks whether if the first call returns true (which is
pretty straightforward, as numeric).

I'm pretty sure there are more complicated reasons... Any "bytecode
expert" to enlighten my day?
Is there a simple way to disable tail calls optimization, with no side
effects (which excludes return(f()+0))?

-- 
Geoffroy Carrier

P.S.: I also recently started using lua for work. So I might have more
serious messages in the future. Maybe not.