help-octave
[Top][All Lists]
Advanced

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

octave vs. matlab vectorization


From: matt
Subject: octave vs. matlab vectorization
Date: Mon, 14 Sep 2009 16:33:03 +0100

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.



reply via email to

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