[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Spelling corrector
- From: Enrico Colombini <erix@...>
- Date: Mon, 07 Jul 2014 14:22:39 +0200
On 07/07/2014 13.30, Paco Zamora Martínez wrote:
The bottleneck of the code is in the function 'edits1'
From a superficial glance at spell.lua:
> yield( splits[i-1][1]..word[i+1]..word[i]..splits[i+2][2] )
Do you really need to concatenate here, or could you instead pass a
table with separate entries and concatenate only when needed?
Also, you could try using table.concat() instead of .. (it could be
faster... or not).
You could also keep an eye on memory usage to see if this is really an
allocation problem.
Lots of temporary strings seem to be created (e.g. by
word_str:sub(...)); perhaps the code could be restructured to reduce
their number as much as possible?
Last but not least:
> for i=1,#word_str do for j=1,#alphabet do
I did not try to follow the code, so I may be dead wrong, but nested
loops like this usually raise a O(n^2) efficiency red flag, especially
because you perform string concatenation inside them.
--
Enrico