help-octave
[Top][All Lists]
Advanced

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

RE: CPU time, Octave vs MATLAB


From: Henk Borsje
Subject: RE: CPU time, Octave vs MATLAB
Date: Tue, 10 Mar 2020 16:42:46 +0100

 

 

From: Ardid, Salva <address@hidden>
Sent: Tuesday, March 10, 2020 4:22 PM
To: Ian McCallion <address@hidden>; Rory Conolly <address@hidden>
Cc: Kai Torben Ohlhus <address@hidden>; Octave Help <address@hidden>
Subject: Re: CPU time, Octave vs MATLAB

 

De: Help-octave <help-octave-bounces+salva.ardid=address@hidden> de part de Ian McCallion <address@hidden>
Enviat el: dimarts, 10 de març de 2020 10:50
Per a: Rory Conolly <address@hidden>
A/c: Kai Torben Ohlhus <address@hidden>; Octave Help <address@hidden>
Tema: Re: CPU time, Octave vs MATLAB

 

On Tue, 10 Mar 2020 at 14:31, Rory Conolly <address@hidden> wrote:
>
>
>
> On Tue, Mar 10, 2020 at 10:08 AM Kai Torben Ohlhus <address@hidden> wrote:
>>
>> On 3/10/20 9:39 PM, Rory Conolly wrote:
>> > I have a program that describes biological mechanisms of cancer. Running
>> > the code in MATLAB takes 112 minutes. The almost identical code in
>> > Octave takes about 10 hr, so about 5 times slower. Is this an expected
>> > difference between Octave and MATLAB or more likely due to something in
>> > my code? Code is hundreds of lines over several files.
>> >
>> > - Rory
>> >
>>
>> Dear Rory,
>>
>> Unless you present (a meaningful portion of) your code, it is fortune
>> telling and blind guessing what could be wrong.  Most likely your code
>> is not properly vectorized [1] and uses lots of nested loops, e.g.
>>
>> for k = 1:P
>>   for i = 1:M
>>     for j = 1:N
>>       A(i,j) = A(i,j) + B(i,j);
>>     endfor
>>   endfor
>> endfor
>>
>> You can make use of profiling [2] to find the bottlenecks.
>>
>> HTH,
>> Kai
>>
>> [1] https://nam05.safelinks.protection.outlook.com/?url="">
>> [2]
https://nam05.safelinks.protection.outlook.com/?url="">
>
>
>
> Kai, thanks for your input. My question is more about the relative speed of Octave vs MATLAB. My code was originally developed in MATLAB and is vectorized. The code reads parameter values from an Excel file. The Octave call to Excel requires the file extension while the MATLAB call does not. So that’s the only modification of the code running in Octave. So the two codes are pretty much identical, but the Octave code runs much more slowly. Happy to provide the code but it’s in several files and probably a thousand or more lines.

Octave generally is nothing like 5 times slower than Matlab. My own
code for example runs at about the same speed. However I believe
Matlab has worked hard to improve nested loop performance in
particular. Hence Kai's suggestions.

Vectorisation also improves quality and readability. Go for it!

Cheers... Ian


Hi Rory,

To be a bit more specific on this

Matlab has worked hard to improve nested loop performance

The difference between Matlab and Octave here is related to the JIT compiler.


reply via email to

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