help-octave
[Top][All Lists]
Advanced

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

Re: octave vs. matlab vectorization


From: Judd Storrs
Subject: Re: octave vs. matlab vectorization
Date: Mon, 14 Sep 2009 12:07:33 -0400

Matlab has used a JIT compiler for a while now so the vectorization penalty in loops often isn't nearly as severe as it once was. In the Q&A of a sales presentation a few years ago, I remember it was mentioned that Matlab's JIT compiler is able to recognize and vectorize some loops more efficiently than others. Octave doesn't have JIT.

--judd



On Mon, Sep 14, 2009 at 11:33 AM, 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.

cheers,

matt.

_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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