Login
7 branches 0 tags
Ben (X13/Arch) Added another benchmark 6d10d4d 3 years ago 761 Commits
nujel / benchmark / wc / lua.lua
file = io.open ("benchmark/bib.txt", "r")

con = file:read("*a")

local nl = 0;
local nw = 0;
local nc = con:len();
local inWord = false;

for i = 1, con:len() do
    local c = con:sub(i,i)
    if (c == " ") then
        inWord = false;
    else
        if (c == "\n") then
            inWord = false;
            nl = nl + 1;
        else
            if (not inWord) then
                nw = nw + 1
            end
            inWord = true
        end
    end
end

print ("Lines: " .. nl)
print ("Words: " .. nw)
print ("Characters: " .. nc)

io.close(file)