Differences in Matlab/Octave processing time
Stuart Brorson
sdb at cloud9.net
Fri May 30 09:34:00 CDT 2008
> I've got a Matlab code which I want to run on Octave. With Matlab this
> program takes about 5 minutes under Windows XP on a Intel Pentium 4 2.4 GHz
> to make an output .mat. With Octave on the same computer, it took ages...
> maybe 30 times more processing time. Same thing happens for Octave with the
> same version (2.9.15) on a Linux machine (Intel Xeon 2.8 GHz). Is anybody
> have a reason why? Is it because of Octave or the code itself?
If you use lots of for loops, expect Octave to be much slower than
Matlab. The best way to improve the performance of Octave code is to
vectorize your code as much as possible.
As I understand it, there are at least two reasons for this (I await
correction if I am wrong):
1. Matlab has implemented a "just in time" compiler, which finds
loops in your code and optimizes them. Octave is only interpreted, so
each loop iteration requires lots of overhead processing.
2. Matlab uses fast integer math for the loop iterator. Octave does
something else -- it may even treat the iterator as a double array
object, just like everything else. (I could be wrong here.) That
makes it very slow to take apart the iterator, increment it, etc.
> The code reproduce a particle in cells simulation. I don't know how many
> loops it makes.
For loops -> slow code.
Stuart
More information about the Help-octave
mailing list