help-octave
[Top][All Lists]
Advanced

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

How to handle slow array loops?


From: otrov
Subject: How to handle slow array loops?
Date: Thu, 02 Jun 2011 03:01:05 +0200

Hi,

please consider this simplified example:

---------------------------------------
function h = loop(range)

h = zeros(1,1000 + 1);
xx = rand(2, range);

for i=1:range
  for j=1:2
    t = round(xx(j, i) * 1000 + 1);
    h(t) = h(t) + 1;
  end
end

endfunction
---------------------------------------

'tic; h = loop(1000000); toc'

on 2.4GHz Pentium 4 with 1GB RAM takes more then 340 seconds

Every added zero in that range adds another zero to test time

As this loop in Fortran [1] performs ~3000 times faster I'm 
wondering
what can I do to speed up this Octave code?

Also some explanation why this is so slow is much appreciated


Thanks in advance


[1] Fortran through C interface, pure Fortran wasn't tested



reply via email to

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