lua-users home
lua-l archive

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


Hi

> But for more "real" programs (such as life.lua), `luaV_execute'
> gets ~20% of the time, hash indexing (luaH_get and relatives)
> gets other 20%, and the other 60% goes to many small tasks, each
> taking less then 5% (string manipulation, garbage collection,
> library calls, etc.).
For example, you can speed up Life.lua about twice adding a temporary 
variable (out2) to collect the character to write out:

-- output the array to screen
function _CELLS:draw()
  local out="" -- accumulate to reduce flicker
  local y=1
  while y <= self.h do
    local out2="" -- new variable
    local x=1
    while x <= self.w do
      out2=out2..(((self[y][x]>0) and ALIVE) or DEAD)
      x=x+1
    end
    out=out..out2.."\n"
    y=y+1
  end
  write(out)
end

This new version reduces the length of the used strings, therefore 
reduces also the frequency of the garbage collection.

Hopefully Life.lua given with Lua 4.0 beta will use the For statement.

Bye
Mauro