lua-users home
lua-l archive

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



On Oct 18, 2007, at 21:42, Mariano Kamp wrote:

But anyway, there has been no solution yet, right?

Well... depends how badly you want to mangle your code :P

Using find() before match() speed up things quite a bit and put them on par with the ruby version:

for aLine in io.lines() do
    if aLine:find( 'GET /ongoing/When/200x/' ) then
        local aPage = aLine:match( 'GET /ongoing/When/200x/([^%.]+) ' )

        if aPage then
            aMap[ aPage ] = ( aMap[ aPage ] or 0 ) + 1
        end
    end
end

gmatch: 0.41 real 0.30 user 0.05 sys
find:   0.20 real 0.16 user 0.01 sys
ruby:   0.20 real 0.16 user 0.01 sys

LuaProfiler:

io.lines 31 %
find     26 %
sort     13 %
match    10 %

Is there something like Ruby's ARGF.each_line? In Ruby you would get all the lines of all the files specified on the command line, not just the lines you'd get from STDIN.

Hmmm... not out of the box as far as I know... io.stdin by default... in Lua, you usually have to bring your own batteries :P