how to improve the speed of octave?
przemek at jazz.ncnr.nist.gov
Fri Sep 15 15:16:10 CDT 2006
We all remember that you compile your own Octave; this has already
caused some complications, e.g. when you didn't have the zlib library
on your system (although it did help to fix a related bug). Octave
really works better if you compile with with the optimal set of
libraries such as FFTW and Atlas and zlib. Unfortunately :) it will
also compile in a reduced environment.
Is there a chance that you'd install one of the versions compiled by
the Octave maintainers, who take care of including the best-of-breed
libraries? On RPM systems (Fedora/Mandrake/RedHat/etc) it is as
simple as 'yum install octave-forge'; on Debian APT systems it is
'apt-get install octave-forge'.
To address your question directly, Octave, when linked fast libraries
such as FFTW and Atlas, is quite competitive on the raw numerical
calculations. Most of the time the slowness is caused by interpreted
loops, operating on small data chunks, rather than giving a chance to
the numerical libraries to rip through whole large arrays at a time
(traditionally, this is called 'vectorizing').
Here's a good example: a 89MB array that we total up in a vectorized
way using the sum() builtin, and using explicit loops:
Elapsed time is 0.321 seconds.
tic; summa=0; [M,N]=size(a); for i=1:M; for j=1:N; summa+=a(i,j); end; end; toc
Elapsed time is 233.91 seconds.
In this case, the explicit loop is slower by a factor of 700! Such
slowdown is inevitable, but, unfortunately, it is more pronounced in
Octave than in Matlab.
Of course, not all loops are as easy to vectorize as this one;
sometimes it requires Octave code which may be difficult to write and
hard to read/understand, and sometimes it's just plain impossible.
More information about the Help-octave