help-octave
[Top][All Lists]
Advanced

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

Re: octave vs. matlab vectorization


From: Jaroslav Hajek
Subject: Re: octave vs. matlab vectorization
Date: Mon, 14 Sep 2009 19:51:43 +0200

On Mon, Sep 14, 2009 at 5:33 PM, matt <address@hidden> wrote:
> i have used octave exclusively for a number of years and just
> recently had to use matlab for teaching purposes.
>
> since i was raised to vectorize loop structures whenever possible, i
> thought i would illustrate the the speed-up for the students in the
> class by comparing execution time for two codes--code 1 with loops,
> and code 2 vectorized.
>
> here is code 1:
>
> t0=clock;
> for m=1:1000000
>        q=zeros(1,10);
>        for k=1:10,
>                tmp=k^2;
>                if tmp>50,
>                        q(k)=tmp;
>                else
>                        q(k)=0;
>                end
>        end
> end
> etime(clock,t0)
>
> here is code 2:
>
> t0=clock;
> for m=1:1000000
>        q=zeros(1,10);
>        tmp=(1:10).^2;
>        q=tmp.*(tmp>50);
> end
> etime(clock,t0)
>
> on my laptop, octave (3.0.5) takes 200 secs for the first code and
> just 24 secs for the second--i thought i had proved my point.
>
> however, on the department server (admittedly a much faster machine),
> matlab ground through the first code in 0.82 secs while the second
> code took 4.3 secs.
>
> so, my question: has matlab been optimized for loops? is there some
> sort of compilation going on? any insight gratefully received. i have
> been writing code in octave for a while now and had assumed it would
> almost be a straight port to matlab.
>

Octave mailing list is not the best place to ask technical questions
about Matlab.
But yes, one of the primary performance differences between Octave and
Matlab is that Octave is purely interpreted, while Matlab is JIT
compiled. I think this situation is unlikely to change in the near
future.

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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