octave-maintainers
[Top][All Lists]
Advanced

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

Re: Octave vs Scilab


From: Jaroslav Hajek
Subject: Re: Octave vs Scilab
Date: Thu, 7 Oct 2010 17:05:45 +0200

On Wed, Oct 6, 2010 at 11:40 PM, John W. Eaton <address@hidden> wrote:
> On  6-Oct-2010, Fotios Kasolis wrote:
>
> | So I did not manage to reproduce the example which was like 3 times faster
> | but here is another example (not that bad)
> |
> | Windows 7 with binaries Octave 3.2.4 and Scilab 5.2.2 on intel i7 720
> |
> | octave.exe:1> xmpl
> | 32.430
> |
> | ->exec('C:\Users\fotios\Desktop\xmpl.sce', -1)
> | 22.411
> |
> | where xmpl contains the very intelligent code shown below
> | N = 2000
> | A = zeros(N,N);
> | tic();
> | for i = 1:N
> |   for j = 1:N
> |     A(i,j) = i^2 + j^2;
> |   end
> | end
> | time = toc();
> | disp(time)
>
> On my system with the most recent Octave snapshot (3.3.52) I see
> 31.422 seconds for Octave and 32.9 seconds for Scilab.  And for the
> more intelligent
>
>  tic ();
>  N = 2000;
>  tmp = (1:N).^2;
>  A = repmat (tmp, N, 1) + repmat (tmp', 1, N);
>  toc ();
>
> I get about .2 seconds for Octave and and error about repmat being
> undefined in Scilab.  Using kron instead:
>
>  tic ();
>  N = 2000;
>  t1 = (1:N).^2;
>  t2 = ones (N, 1);
>  A = kron (t1, t2) + repmat (t1'; t2');
>  toc ();
>

This is actually the kind of task bsxfun is ideal for. Try:

t = (1:N).^2;
A = bsxfun (@plus, t.', t);



reply via email to

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