lua-users home
lua-l archive

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


>> function f(a, b, z)
>>   return a * exp(i*z) + b
>> end
>> 
>> The problem of the function above is that it looks clear and simple
>> but in reality it is a disaster in term of run-time execution because
>> a lot of small objects have to be created on the heap every time that
>> it is executed.
> 
> Indeed. I fell the same pain when I write bindings for math operations
> (and I've written several). I wish Lua told me that it wants a temporary
> value. I could then use static allocation for those.
> 

I was curious to find out how bad the disaster is, so I put that
function in a loop that runs a million times, using the complex
implementation in NumLua 0.3, and compared it with the state of the
art in open-source numerical computation.
    Lua 5.1:    4.1 seconds
    LuaJIT 2.0: 2.9 seconds
    Octave:     0.43 seconds (vectorized)
               34 seconds (not vectorized) 
NumLua will also have vectorized operations, but 0.3 is still full
of TODO's and FIXME's as far as that goes.

Dirk