[Top][All Lists]

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

Re: Performance test

From: Carlo de Falco
Subject: Re: Performance test
Date: Thu, 12 Mar 2009 01:21:01 +0100

On 11 Mar 2009, at 23:57, DaNiMoTh 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 )

tic ; kernel(magic(100)) ; toc
Elapsed time is 0.052000 seconds.

octave:1> tic ; kernel(magic(100)) ; toc
Elapsed time is 56.9406 seconds.

time ./a.out
real    0m0.075s

Why this difference?
Where is the bottleneck of Octave?

In the 'for' loop,

it is well known that writing vectorized code gives a dramatic speed- up in Octave.
For exmple on my machine, by rewriting your function as

function G = kernel2(A)

colonne_m = columns(A);
righe_n = rows(A);
G = zeros(righe_n,righe_n);
for i = 1:righe_n
      for j = 1:colonne_m
        G(i,j) = (A(i,:)*A(j,:)'+1).^3;

I get

>> tic ; B2=kernel2(magic(100)) ; toc
Elapsed time is 0.60966 seconds.

whereas your original function gives

>> tic ; B=kernel(magic(100)) ; toc
Elapsed time is 48.349 seconds.

and of course

>> norm(B-B2)
ans = 0

I'm sure this can be improved even further

There is some documentation about this?

yes, this is mentioned in the FAQ:

Many Thanks. ( Please CC'd me in reply as I'm not a follower of this list )


reply via email to

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