Lua string to number parsing speed optimization
snippet in lua

Lua string to number parsing speed optimization

user9468

local gmatch, s = string.gmatch, 0

for line in io.lines(arg[1]) do
  for n in gmatch(line, '%d+') do
    s = s + n  -- converting string to number is automatic here
  end
end

print(s)