help-octave
[Top][All Lists]
Advanced

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

Re: compare the executive speed with Matlab


From: Sergei Steshenko
Subject: Re: compare the executive speed with Matlab
Date: Fri, 2 Jan 2009 11:44:37 -0800 (PST)



--- On Fri, 1/2/09, Jordi Gutiérrez Hermoso <address@hidden> wrote:

> From: Jordi Gutiérrez Hermoso <address@hidden>
> Subject: Re: compare the executive speed with Matlab
> To: "John W. Eaton" <address@hidden>
> Cc: address@hidden, address@hidden, "Howard" <address@hidden>
> Date: Friday, January 2, 2009, 11:21 AM
> 2009/1/2 John W. Eaton <address@hidden>:
> > On  2-Jan-2009, Sergei Steshenko wrote:
> >
> > | Well, IIRC, if I need to calculate, say,
> 'sin' function for a vector of
> > | ~150000 elements, 'octave' speed is ~5 times
> slower than the one of the
> > | equivalent code in "C".
> >
> > How about posting an actual working example so we can
> see exactly what
> > it is you are comparing?  Perhaps you are doing
> something stupid, and
> > your comparison is not valid.  Or perahaps there is a
> good reason that
> > Octave must do extra work compared to the C version.
> 
> It's quite easy to come up with this example. In fact,
> he more or less
> gave the example. He's talked about this example before
> in the mailing
> list too.
> 
> In Octave,
> 
>      octave:1> v = [1:15e6];
>      octave:2> tic, sin(v); toc;
>      Elapsed time is 1.39321 seconds.
> 
> In C,
> 
>     #include <math.h>
> 
>     int main(){
>       int N = 15000000;
>       int i;
>       double d;
>       for(i = 0; i < N; i++)
>        d = sin( (double) i);
>     }
> 
> then
> 
>      address@hidden:~$ gcc foo.c -o foo -lm && time foo
> 
>      real     0m1.035s
>      user     0m1.024s
>      sys      0m0.012s
> 
> It's not a very noticeable difference, but I do wonder
> why there is
> one at all.
> 
> - Jordi G. H.

My experiment was more severe.

In both cases I had prepared array (vector in 'octave') of 'sin' function
arguments, and I wasn't benchmarking the preparation part, I was 
benchmarking just the 'sin' computation part.

Your experiment is not fair in its "C" part since it has int -> double
conversion while 'octave' part doesn't have it.

I was also measuring time _inside_ the "C" program - to avoid whatever
startup time artifacts.

Regards,
  Sergei.


      



reply via email to

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