lua-users home
lua-l archive

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


To open a whole new can of worms...

Could this code be made faster by making "word" a local variable?

i.e:

#!/usr/local/bin/lua

words = {}
numWords = 0

print ("-mark- beginning read")

do
local word;

for word in io.lines("/usr/dict/words") do
    numWords = numWords + 1
    words[word] = 1
end
end

print ("-mark- beginning delete")

do
local word;

deletedWordCount = 0

for word in io.lines("/usr/dict/words") do
    if words[word] then
        words[word] = nil
        deletedWordCount = deletedWordCount + 1
        if ( math.mod(deletedWordCount, 1000) == 0 ) then
            print("-mark- " .. deletedWordCount .. " " .. table.getn(words))
        end
    end
end
end