help-octave
[Top][All Lists]
Advanced

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

Re: Performance test


From: Jaroslav Hajek
Subject: Re: Performance test
Date: Thu, 12 Mar 2009 07:45:56 +0100

On Wed, Mar 11, 2009 at 11:57 PM, DaNiMoTh <address@hidden> wrote:
> Hello to all.
>
> I've tried to execute the same routine (see attachment) with matlab,
> octave and a C program.
>
> There are the results ( both of programs under Linux )
>
> MatLab:
>>> tic ; kernel(magic(100)) ; toc
> Elapsed time is 0.052000 seconds.
>
> Octave:
> octave:1> tic ; kernel(magic(100)) ; toc
> Elapsed time is 56.9406 seconds.
>
> C:
> time ./a.out
> real    0m0.075s
>
> Why this difference?
> Where is the bottleneck of Octave? There is some documentation about this?
>
> Many Thanks. ( Please CC'd me in reply as I'm not a follower of this list )
>
> kernel.m :
>
> function G = kernel(A)
>
> colonne_m = size(A)(2);
> righe_n = size(A)(1);
>
> G = zeros(righe_n,righe_n);
>
> for i = 1:righe_n
>       for j = 1:colonne_m
>               for k = 1:colonne_m
>                       G(i,j) = G(i,j)+(A(i,k)*A(j,k));
>               endfor
>               G(i,j) = (G(i,j)+1)^3;
>       endfor
> endfor
>

Octave is all about vectorized code. So is Matlab, but it is able to
compile simple loops for you using JIT. Implementing JIT in Octave is
a nontrivial task and will probably not happen easily without funding.

Anyway this loop is completely vectorizable, just use:

function G = kernel(A)

G = (1 + A*A').^3;

and you'll get the result much faster (for large matrices, even
significantly faster than with your loop coded in C,
at least if you have good BLAS).

cheers


-- 
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]