lua-users home
lua-l archive

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


> On Thu, Oct 7, 2010 at 7:40 AM, Michal Kolodziejczyk <miko@wp.pl> wrote:
>> (Of course "don't optimize" means "don't use implementation specific
>> hack", but you still should use efficient algorithms).
> 
> among those, the first one is to reuse.   tables, in this case.  i
> don't think LuaJIT's allocator/GC is 10 times faster than stock Lua's.


Thanks for all your suggestions.
Before jumping into LuaJIT, I'm still experiencing Lua:

So, here is my new attempt :
It runs from 22 seconds down to 16,7 sec  in a specific test.

local tr, tg, tb = {}, {}, {}

function median_rgb( x0, y0, radius )
  local N = 0
  for y = y0-radius, y0+radius do
      for x = x0-radius, x0+radius do
           N = N + 1
           tr[N], tg[N], tb[N] = get_rgb( x, y )
      end
  end
table.sort (tr)
table.sort (tg)
table.sort (tb)

Anyway, as I'm writing an extension for an app, I've already
code few things in C.... probably will write later this function in C too.
But then, if I surely gain a lot of time with the 2 for loop being in C, what the
cost of the overhead to call again and again this C function ?
Or put it in another way,
is the cost of calling a Lua function is the same as calling the equivalent C function ?

Is there some guidances somewhere to know the good balance ?

And another question coming out of your answers :
writing few functions like this one in C,
is there still a gain to use LuaJIT then ?

Hope I'm clear ( sorry my mother tongue is French )

Thierry