help-octave
[Top][All Lists]
Advanced

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

Re: speed of octave


From: David Bateman
Subject: Re: speed of octave
Date: Thu, 06 Sep 2007 23:53:22 +0200
User-agent: Thunderbird 1.5.0.7 (X11/20060921)

frank wang wrote:
> while trying to find the speed of octave, scilab and matlab, I found
> the following test code and decided to run it on octave 2.9.13
> (window) and matlab 7.1a. The result shows that octave is 30 time
> slower than matlab.
> 
> in Matlabe: tic; z=bench1(10); toc;
> Elapsed time is 0.015060 seconds.
> 
> in octave: tic; z=bench1(10); toc;
> Elapsed time is 2.704300 seconds.
> 
> function [z]=bench1(n)
> for i=1:n,
>     for j=1:1000,
>         z=log(j);
>         z1=log(j+1);
>         z2=log(j+2);
>         z3=log(j+3);
>         z4=log(j+4);
>         z5=log(j+5);
>         z6=log(j+6);
>         z7=log(j+7);
>         z8=log(j+8);
>         z9=log(j+9);
>     end
> end
> z = z9;
> 
> Thanks
> 
> Frank


Frank,

This is just an example of poorly written code and matlab is more
forgiving of poorly written code with their JIT compiler. Its silly to
talk about vectorization as the above makes no use of the iterations of
the loop, but read the document

http://www.mathworks.com/support/tech-notes/1100/1109.html

the advice here applies equally well to Octave. Yes matlab is faster
than Octave with for-loops, Use vectorization and that advantage
disappears. For the very few cases where you can't vectorize, convert
the code to a compiled language in the form of a mex- or oct-file.

D.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]