lua-users home
lua-l archive

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


Emmanuel Oga wrote:
> I'm pretty happy with the 24x speed up for lua and 8x speed up for
> luajit but since I'm running the function over thousands of strings
> I'm wondering if a little more speed could be squeezed on the C side.

Not unexpectedly, I'm wondering why not squeeze out a little more
speed on the Lua side:

  local byte = string.byte
  local function ssm(pattern, str, start)
    local pidx = start or 1
    for i=1,#str do
      if byte(str, i) == byte(pattern, pidx) then pidx = pidx + 1 end
      if pidx > #pattern then return true end
    end
    return pidx
  end

With LuaJIT that's 8x faster than the original Lua code.
I.e. pretty close to the performance of C.

--Mike