lua-users home
lua-l archive

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

On 17 February 2011 23:03, Mike Pall <> wrote:
> T T wrote:
>> > 2011/2/17 T T <>:
>> >> For N=1e8 I get 0.91sec with MATLAB and 0.68sec with LuaJIT-2.  Pretty
>> >> close I would say.
>> That got me thinking.  Mike, do you do some special optimization for 'a=a+1'?
>> I tried with 'a=a+sin(a)' instead and got only 20% difference between
>> MATLAB and LuaJIT.
> Any speedup you're measuring is relative to the expensiveness of
> the underlying instructions. The example loop is dominated by the
> latencies of the respective FP operations. FP adds take 3 cycles
> each and sin() takes 40-100 cycles.

Duh, but of course.  The division in 'sum=sum+1/n' is similarly
expensive, so that explains it.

> The latter obviously dominates the total time, so MATLAB's
> overhead is less pronounced on the sin() loop. In fact I'd expect
> it to take roughly the same time as LuaJIT there, but apparently
> MATLAB's compiler is ... errm ... 'suboptimal'.

It certainly is no match for luajit.  The factor of 3.6 difference for
the case of 'a=a+1', shows that quite quite conclusively.  But truth
to be told, you typically want do some useful work in a loop and then
a bit of overhead there doesn't hurt so bad.  What hurts much more is
function calls, where MATLAB drops the ball completely.  LuaJIT is a
clear winner from that perspective.

If only those small loops run faster... Just teasing ;)