lua-users home
lua-l archive

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


Hi all,

I'm implementing, just for fun, a Lua version of the spelling corrector of Peter Norvig.

Lua spelling corrector: https://github.com/pakozm/lua-spell-correct

Orignal spelling corrector in Python: http://norvig.com/spell-correct.html

I'm doing it using coroutines to avoid the overhead of several list traversals, but I'm facing efficiency problems. The Lua code is between 3 and 4 times slower than the original Python code. I'm wondering if it is possible to discuss where is the code performing bad. The bottleneck of the code is in the function 'edits1', which is executed several times to modify the string with 2 edition operations.

I have tested the following changes:

1) Implemented using tables instead of coroutines. The performance is close in both implementations.

2) Use table.concat instead of string concatenation. It performs worst with table.concat.

3) Use string.format instead of string concatenation. It performs worst with string.format.

Many thanks, I hope anyone could enjoy with this exercise :-)

Pako ZM :)
http://cafre.dsic.upv.es:8080/~pako/