[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: octave vs. matlab vectorization
From: |
Francesco Potorti` |
Subject: |
Re: octave vs. matlab vectorization |
Date: |
Mon, 14 Sep 2009 18:31:35 +0200 |
>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.
A ratio of 8.3:1
>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.
A ratio of 5.2:1. Not quite the same, but I think the point is proven
nonetheless.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/