help-octave
[Top][All Lists]

## Re: Octave compared to Matlab

 From: Mario Storti Subject: Re: Octave compared to Matlab Date: Fri, 14 Aug 1998 11:46:02 -0300

```>>>>> On Fri, 14 Aug 1998 16:16:29 +0200 (MET DST),

> On Fri, 14 Aug 1998, Mario Storti wrote:

>>
>> So that the function is compiled only once. Even more you can avoid the
>> time spent in checking the time stamp of the file with the
>> configuration variable `ignore_function_time_stamp'.
>>

> Is it then true, that to make a calculation with loops takes
> about the same time as with matrix formulation of the same problem?

> /Peter Waller

No.  Execution of loops in Octave are intrinsically inefficient (as
compared with Fortran or C), even if you don't call functions inside
the loop. For instance with the 'cross.m' function I sent to you
yesterday, the vector form

> octave> tic ; c=cross(a,b); toc
> ans = 0

is far much faster than the loop

> octave> tic; for k=1:n;   c(k,1)=a(k,2).*b(k,3)-a(k,3).*b(k,2); \
c(k,2)=a(k,3).*b(k,1)-a(k,1).*b(k,3);  \
c(k,3)=a(k,1).*b(k,2)-a(k,2).*b(k,1); endfor; toc
> ans = 17

But the loop doesn't change very much if calling a function inside.

> octave> ignore_function_time_stamp="all";
> octave> tic; for k=1:n;   c(k,:)=cross(a(k,:),b(k,:)); endfor; toc
> ans = 21
> octave> ignore_function_time_stamp="system";
> octave> tic; for k=1:n;   c(k,:)=cross(a(k,:),b(k,:)); endfor; toc
> ans = 21

BTW, apparently, time stamp checking is not too much comsuming in this
case.

I tried with the `cross.m' that cames with octave too and it gave me an
elapsed time of 46. This is because it does a lot of error checking.

(I run all the examples in a Linux/Pentium 133Mhz, Octave 2.0.13. I
used n=3000. I used tic/toc but there were no interferences from other
processes on the system.)

Regards,

Mario

%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%%%%%%<>%
Mario Alberto Storti                           | Fax: (54)(42) 55.09.44 |
Centro Internacional de Metodos Computacionales| Tel: (54)(42) 55.91.75 |
en Ingenieria - CIMEC (INTEC/CONICET-UNL)    |........................|
INTEC, Guemes 3450 - 3000 Santa Fe, Argentina                           |