lua-users home
lua-l archive

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


On Thu, Feb 17, 2011 at 11:26, T T <t34www@googlemail.com> wrote:
> I get 9.30sec on my machine.  An equivalent Lua code takes 2.55sec.
> So MATLAB is clearly not as good as luajit, but not as terrible as
> some would like to make it.
>

Try this:

sh$ cat bmark_euler.m
% Benchmark: Euler constant
% Run as: sh$ time matlab -nodesktop -nosplash -nojvm -r bmark_euler
tic
sum= 0;
N= 1E7;
for n=1:1:N
  sum = sum + 1/n;
end
euler= sum - log(N);
fprintf('N    = %G\n', N);
fprintf('euler= %G\n', euler);
toc
quit
%EoF

sh$ matlab -nodesktop -nosplash -nojvm -r bmark_euler
>> N    = 1E+07
euler= 0.577216
Elapsed time is 14.002463 seconds.

sh$ <0> time lua bmark_euler.lua
N    = 1E+07
euler= 0.577216

lua bmark_euler.lua  0.33s user 0.00s system 98% cpu 0.337 total

The performance ratio is 40 times in favor of Lua-5.1.4 *interpreter*.
I guess LuaJIT-2 will be even better.
MATLAB sucks on loops!

Here is my system info:

*M A T L A B (R) Version 7.10.0.499 (R2010a) 64-bit
* Lua-5.1.4 interpreter
* Linux CentOS release 5.5 x64 Linux 2.6.18-194.26.1.el5
* Intel(R) Xeon(R) CPU  E5530  @ 2.40GHz () 4x4 cores, 72GB RAM

--Leo--