compare the executive speed with Matlab

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

compare the executive speed with Matlab

Howard-33
Hi Octave,

I am a new user with Octave 3.0.3. It is very much appreciated of this
good software.

I'm wondering the executive speed compared with Matlab. I found Octave's
executive time is 10 times slower than Matlab on Windows. (I also try
Octave on Linux, but it is still slower than Matlab on Windows) Some
People discussed this issue on a forum. They said it is because Octave
is not good at Loop code. However, even though I run non-loop code on
Octave and Matlab. Octave's executive time is still much slower than
Matlab.

Do you think it is normal that Octave's executive speed slower than
Matlab? or it is my configuration's problem?

Thanks for your time

Best regards,

Howard Su

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Michael Goffioul
It's usually much appreciated that such comment comes
with a concrete example demonstrating the problem.

Saying "octave is slow" is quite vague and nobody will
try to help you, because we just can't figure out why
octave is slow for you. Saying "octave is slower than
Matlab on this piece of code" is much more helpful.

Michael.


On Thu, Jan 1, 2009 at 6:47 PM, Howard <[hidden email]> wrote:

> Hi Octave,
>
> I am a new user with Octave 3.0.3. It is very much appreciated of this
> good software.
>
> I'm wondering the executive speed compared with Matlab. I found Octave's
> executive time is 10 times slower than Matlab on Windows. (I also try
> Octave on Linux, but it is still slower than Matlab on Windows) Some
> People discussed this issue on a forum. They said it is because Octave
> is not good at Loop code. However, even though I run non-loop code on
> Octave and Matlab. Octave's executive time is still much slower than
> Matlab.
>
> Do you think it is normal that Octave's executive speed slower than
> Matlab? or it is my configuration's problem?
>
> Thanks for your time
>
> Best regards,
>
> Howard Su
>
> _______________________________________________
> Help-octave mailing list
> [hidden email]
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko



--- On Fri, 1/2/09, Michael Goffioul <[hidden email]> wrote:

> From: Michael Goffioul <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: "Howard" <[hidden email]>
> Cc: [hidden email]
> Date: Friday, January 2, 2009, 6:31 AM
> It's usually much appreciated that such comment comes
> with a concrete example demonstrating the problem.
>
> Saying "octave is slow" is quite vague and nobody
> will
> try to help you, because we just can't figure out why
> octave is slow for you. Saying "octave is slower than
> Matlab on this piece of code" is much more helpful.
>
> Michael.
>

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".

Of course, I'm not talking about using loops in 'octave' - just a plain
simple operation on vector.

Since I've discovered this I "outsource" such stuff to "C", i.e. I find it
more efficient for what I need to do to invest extra effort in writing
the needed code in "C".

I mean, I'm trying to implement in 'octave' relatively complex algorithmic
stuff, and where possible to use "C" for straightforward massive
calculations.

Regards,
  Sergei.





     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

John W. Eaton
Administrator
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.

jwe
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko



--- On Fri, 1/2/09, John W. Eaton <[hidden email]> wrote:

> From: John W. Eaton <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "Howard" <[hidden email]>, "Michael Goffioul" <[hidden email]>, [hidden email]
> Date: Friday, January 2, 2009, 10:30 AM
> 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.
>
> jwe

I'd rather prefer to continue acting acting under the assumption I'm doing
something stupid.

Thanks,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Jordi Gutiérrez Hermoso
In reply to this post by John W. Eaton
2009/1/2 John W. Eaton <[hidden email]>:

> 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

     jordi@Iris:~$ 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.
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko



--- On Fri, 1/2/09, Jordi Gutiérrez Hermoso <[hidden email]> wrote:

> From: Jordi Gutiérrez Hermoso <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: "John W. Eaton" <[hidden email]>
> Cc: [hidden email], [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 11:21 AM
> 2009/1/2 John W. Eaton <[hidden email]>:
> > 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
>
>      jordi@Iris:~$ 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.


     

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

John W. Eaton
Administrator
In reply to this post by Jordi Gutiérrez Hermoso
On  2-Jan-2009, Jordi Gutiérrez Hermoso wrote:

| It's quite easy to come up with this example. In fact, he more or less
| gave the example.

No, he described the example.  I usually want to see precisely what
the code is that someone is talking about, and I don't want to have to
guess about what that might be.

| He's talked about this example before in the mailing list too.

Then provide a URL for a previous discussion.  Don't assume we can
find previous discussion by searching the web.  We may find something
different from what the OP had in mind.  It helps if we know we are
discussing the same thing, without having to guess.

| In Octave,
|
|      octave:1> v = [1:15e6];
|      octave:2> tic, sin(v); toc;
|      Elapsed time is 1.39321 seconds.

If you want to do comparisons, please use cputime instead of tic/toc.
That way, you can get the user and system CPU time.  The wall clock
time that tic/toc returns is not very useful for comparison purposes.
There could have been other things running on your system when this
code was executed.

| 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
|
|      jordi@Iris:~$ 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.

Some things I can think of:

  Octave has to include a call to the OCTAVE_QUIT macro inside the
  loop, so that the loop can be interrupted.

  There is some overhead for setting up a function call in Octave.

  Space for the result vector must be allocated, and elements of the
  argument vector must referenced.

jwe

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

John W. Eaton
Administrator
In reply to this post by Sergei Steshenko
On  2-Jan-2009, Sergei Steshenko wrote:

| 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.

If we are to keep discussing this, and you continue to claim a factor
of ~5 difference in execution speed, then show us precisely the C code
and the Octave code you are comparing, and exactly how you ran the
comparisons, etc.

So what version of Octave were you using and how did you compile it
(compiler, version, options, OS, etc.)?

Exactly what C code did you use for comparision, and how did you
compile it?

jwe
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Jordi Gutiérrez Hermoso
In reply to this post by Sergei Steshenko
2009/1/2 Sergei Steshenko <[hidden email]>:
> My experiment was more severe.

Show us the experiment, then.

> 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.

That's what I timed too.

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

Actually, I thought that Octave had this conversion too. At any rate,
it doesn't affect the execution speed at all to use double i instead;
I just tried it too.

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

I can't think of any artifacts that could have taken place here. There
is no construction, memory management, whatever. Nothing of the sort.

Just show us the fucking code. And I mean this in a good,
non-confrontational way, and I hope you'll pardon my intensifier. :-)

- Jordi G. H.
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko



--- On Fri, 1/2/09, Jordi Gutiérrez Hermoso <[hidden email]> wrote:

> From: Jordi Gutiérrez Hermoso <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "John W. Eaton" <[hidden email]>, [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 12:21 PM
> 2009/1/2 Sergei Steshenko <[hidden email]>:
> > My experiment was more severe.
>
> Show us the experiment, then.
>
> > 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.
>
> That's what I timed too.
>
> > Your experiment is not fair in its "C" part
> since it has int -> double
> > conversion while 'octave' part doesn't
> have it.
>
> Actually, I thought that Octave had this conversion too. At
> any rate,
> it doesn't affect the execution speed at all to use
> double i instead;
> I just tried it too.
>
> > I was also measuring time _inside_ the "C"
> program - to avoid whatever
> > startup time artifacts.
>
> I can't think of any artifacts that could have taken
> place here. There
> is no construction, memory management, whatever. Nothing of
> the sort.
>
> Just show us the fucking code. And I mean this in a good,
> non-confrontational way, and I hope you'll pardon my
> intensifier. :-)
>
> - Jordi G. H.

Sure, sure.

1) 'octave':

octave:36> angles = pi * (1:1000000) / 1000000;tic; sins = sin(angles); toc
Elapsed time is 0.49532795 seconds.

2) "C":

CPU time took 0.13 seconds at line number 74 of 'benchmark_sin.c' file
Wallclock time took 0.130743 seconds at line #74 of 'benchmark_sin.c' file


; the file is attached ('benchmark_sin.c'), it contains the command line
I used to compile it.

OK, so it's not 5 times, it's more than 3 times.

I think, however, that if I use table representation of 'sin', the ratio
will be the 5 times I vaguely remember.

Regards,
  Sergei.



_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

benchmark_sin.c (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

John W. Eaton
Administrator
On  2-Jan-2009, Sergei Steshenko wrote:

| Sure, sure.
|
| 1) 'octave':
|
| octave:36> angles = pi * (1:1000000) / 1000000;tic; sins = sin(angles); toc
| Elapsed time is 0.49532795 seconds.

Please, use cputime.  Wall clock time is meaningless here as there
could be other things running on your system which affect the timing.

| 2) "C":
|
| CPU time took 0.13 seconds at line number 74 of 'benchmark_sin.c' file
| Wallclock time took 0.130743 seconds at line #74 of 'benchmark_sin.c' file
|
|
| ; the file is attached ('benchmark_sin.c'), it contains the command line
| I used to compile it.
|
| OK, so it's not 5 times, it's more than 3 times.
|
| I think, however, that if I use table representation of 'sin', the ratio
| will be the 5 times I vaguely remember.

So, how did you build Octave, and what version is it?

Here is what I see with Octave 3.0.3 on a Debian AMD64 system.  My
copy of Octave is installed from the Debian package and used GCC 4.3.2
(Debian 4.3.2-1) with -O2 (and no other tricky optimization flags):

  octave:1> angles = pi * (1:1000000) / 1000000;
  octave:2> t = cputime (); sins = sin (angles); cputime () - t
  ans =  0.072004

Here is what I see with your code using the same version of GCC

  $ gcc -mtune=native -march=native -O3 sin-tst.c -lm -lrt
  $ ./a.out
  CPU time took 0.05 seconds at line number 74 of 'sin-tst.c' file
  Wallclock time took 0.0685717 seconds at line #74 of 'sin-tst.c' file

So I don't really see anything to fix here.

jwe
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko



--- On Fri, 1/2/09, John W. Eaton <[hidden email]> wrote:

> From: John W. Eaton <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "Jordi Guti��rrez Hermoso" <[hidden email]>, [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 1:03 PM
> On  2-Jan-2009, Sergei Steshenko wrote:
>

> Please, use cputime.  Wall clock time is meaningless here
> as there
> could be other things running on your system which affect
> the timing.
>

>
>   octave:1> angles = pi * (1:1000000) / 1000000;
>   octave:2> t = cputime (); sins = sin (angles); cputime
> () - t
>   ans =  0.072004

Here are better measurements - forgot to lock CPU frequency originally.

1) octave:

angles = pi * (1:1000000) / 1000000;tic;t = cputime (); sins = sin(angles); fprintf(stdout(), "CPU time: %g\n", cputime () - t);toc
CPU time: 0.140009
Elapsed time is 0.14142704010009765625 seconds.

2) "C":

CPU time took 0.04 seconds at line number 74 of 'benchmark_sin.c' file
Wallclock time took 0.0490916 seconds at line #74 of 'benchmark_sin.c' file

- the same 3+ times.

My 'octave' runs on a 32 bits machine. It uses

-mtune=native -march=native -mfpmath=sse,387 -O2

optimizations.

With this simple 'sin' test -mfpmath=sse,387 changes results:

CPU time took 0.06 seconds at line number 74 of 'benchmark_sin.c' file
Wallclock time took 0.047755 seconds at line #74 of 'benchmark_sin.c' file

- the funny thing is that now CPU time is less than wallclock time which
can't be.

If you count by CPU time, still the speedup is 2+ times for

'octave' version is 3.0.3, it was built using the same gcc-4.3.2 I used
for benchmarking the "C" program.

--Sergei.


     

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

wim van hoydonck
On Fri, Jan 2, 2009 at 10:33 PM, Sergei Steshenko <[hidden email]> wrote:

>
>
>
> --- On Fri, 1/2/09, John W. Eaton <[hidden email]> wrote:
>
>> From: John W. Eaton <[hidden email]>
>> Subject: Re: compare the executive speed with Matlab
>> To: [hidden email]
>> Cc: "Jordi Guti��rrez Hermoso" <[hidden email]>, [hidden email], "Howard" <[hidden email]>
>> Date: Friday, January 2, 2009, 1:03 PM
>> On  2-Jan-2009, Sergei Steshenko wrote:
>>
>
>> Please, use cputime.  Wall clock time is meaningless here
>> as there
>> could be other things running on your system which affect
>> the timing.
>>
>
>>
>>   octave:1> angles = pi * (1:1000000) / 1000000;
>>   octave:2> t = cputime (); sins = sin (angles); cputime
>> () - t
>>   ans =  0.072004
>
> Here are better measurements - forgot to lock CPU frequency originally.
>
> 1) octave:
>
> angles = pi * (1:1000000) / 1000000;tic;t = cputime (); sins = sin(angles); fprintf(stdout(), "CPU time: %g\n", cputime () - t);toc
> CPU time: 0.140009
> Elapsed time is 0.14142704010009765625 seconds.
>
> 2) "C":
>
> CPU time took 0.04 seconds at line number 74 of 'benchmark_sin.c' file
> Wallclock time took 0.0490916 seconds at line #74 of 'benchmark_sin.c' file
>
> - the same 3+ times.
>
> My 'octave' runs on a 32 bits machine. It uses
>
> -mtune=native -march=native -mfpmath=sse,387 -O2
>
> optimizations.
>
> With this simple 'sin' test -mfpmath=sse,387 changes results:
>
> CPU time took 0.06 seconds at line number 74 of 'benchmark_sin.c' file
> Wallclock time took 0.047755 seconds at line #74 of 'benchmark_sin.c' file
>
> - the funny thing is that now CPU time is less than wallclock time which
> can't be.
>
> If you count by CPU time, still the speedup is 2+ times for
>
> 'octave' version is 3.0.3, it was built using the same gcc-4.3.2 I used
> for benchmarking the "C" program.
>
> --Sergei.
>

If I run this benchmark, I see the following figures
(Fedora 10, Intel Core2 Duo @ 2GHz, gcc 4.3.2, gfortran 4.3.2, ifort 11.0):

Octave:
octave:1> angles = pi*(1:1000000)/1000000;
octave:2> t = cputime(); sins = sin(angles); cputime()-t
ans =  0.060991

C (gcc -mtune=native -march=native -O3 benchmark_sin.c -lm -lrt):
CPU time took 0.05 seconds at line number 74 of 'benchmark_sin.c' file
Wallclock time took 0.0486391 seconds at line #74 of 'benchmark_sin.c' file

Fortran (gfortran -mtune=native -march=native -mfpmath=sse,387 -O2-o
fs_gf fortran_sin.f90)
3.69939999999999991E-002

Fortran (intel: ifort -o fs fortran_sin.f90 -O2):
6.000000000000001E-003

Fortran (intel, ifort -o fs fortran_sin.f90 -O2):
5.000000000000000E-003

To conclude, on my computer, for this test, Octave is approximately
as fast as C, gfortran is a little bit faster and ifort is 10 times as fast.

If you want to speed up your code, write the critical parts in Fortran, not C.

Greetings,

Wim


$ cat fortran_sin.f90
program fortran_sin
  implicit none
  integer , parameter   :: dp = selected_real_kind(p=13,r=300)
  integer , parameter   :: n  = 1000000
  integer               :: i
  real(dp) , parameter  :: pi = 3.1415926535897932385_dp
  real(dp)              :: angles(n) , sins(n)
  real(dp)              :: t0 , t1

  call cpu_time(t0)
  angles = real( [(i, i=0,n-1)]/n , kind=dp )
  sins   = pi * sin(angles)
  call cpu_time(t1)
  print *, t1-t0

end program fortran_sin

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

John W. Eaton
Administrator
On  2-Jan-2009, wim van hoydonck wrote:

| To conclude, on my computer, for this test, Octave is approximately
| as fast as C, gfortran is a little bit faster and ifort is 10 times as fast.
|
| If you want to speed up your code, write the critical parts in Fortran, not C.

I don't think that conclusion is justified, but whatever.  Clearly it
is not the language alone, or gfortran would also be 10 times
faster...

In any case, I'm surprised by the 10 times factor.  So how about
comparing the assembly code that is generated.  What is ifort doing
that the others are missing?

jwe
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko
In reply to this post by wim van hoydonck



--- On Fri, 1/2/09, wim van hoydonck <[hidden email]> wrote:

> From: wim van hoydonck <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "John W. Eaton" <[hidden email]>, [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 2:21 PM
> On Fri, Jan 2, 2009 at 10:33 PM, Sergei Steshenko
> <[hidden email]> wrote:
> >
> >
> >
> > --- On Fri, 1/2/09, John W. Eaton
> <[hidden email]> wrote:
> >
> >> From: John W. Eaton <[hidden email]>
> >> Subject: Re: compare the executive speed with
> Matlab
> >> To: [hidden email]
> >> Cc: "Jordi Guti��rrez Hermoso"
> <[hidden email]>, [hidden email],
> "Howard" <[hidden email]>
> >> Date: Friday, January 2, 2009, 1:03 PM
> >> On  2-Jan-2009, Sergei Steshenko wrote:
> >>
> >
> >> Please, use cputime.  Wall clock time is
> meaningless here
> >> as there
> >> could be other things running on your system which
> affect
> >> the timing.
> >>
> >
> >>
> >>   octave:1> angles = pi * (1:1000000) /
> 1000000;
> >>   octave:2> t = cputime (); sins = sin
> (angles); cputime
> >> () - t
> >>   ans =  0.072004
> >
> > Here are better measurements - forgot to lock CPU
> frequency originally.
> >
> > 1) octave:
> >
> > angles = pi * (1:1000000) / 1000000;tic;t = cputime
> (); sins = sin(angles); fprintf(stdout(), "CPU time:
> %g\n", cputime () - t);toc
> > CPU time: 0.140009
> > Elapsed time is 0.14142704010009765625 seconds.
> >
> > 2) "C":
> >
> > CPU time took 0.04 seconds at line number 74 of
> 'benchmark_sin.c' file
> > Wallclock time took 0.0490916 seconds at line #74 of
> 'benchmark_sin.c' file
> >
> > - the same 3+ times.
> >
> > My 'octave' runs on a 32 bits machine. It uses
> >
> > -mtune=native -march=native -mfpmath=sse,387 -O2
> >
> > optimizations.
> >
> > With this simple 'sin' test -mfpmath=sse,387
> changes results:
> >
> > CPU time took 0.06 seconds at line number 74 of
> 'benchmark_sin.c' file
> > Wallclock time took 0.047755 seconds at line #74 of
> 'benchmark_sin.c' file
> >
> > - the funny thing is that now CPU time is less than
> wallclock time which
> > can't be.
> >
> > If you count by CPU time, still the speedup is 2+
> times for
> >
> > 'octave' version is 3.0.3, it was built using
> the same gcc-4.3.2 I used
> > for benchmarking the "C" program.
> >
> > --Sergei.
> >
>
> If I run this benchmark, I see the following figures
> (Fedora 10, Intel Core2 Duo @ 2GHz, gcc 4.3.2, gfortran
> 4.3.2, ifort 11.0):
>
> Octave:
> octave:1> angles = pi*(1:1000000)/1000000;
> octave:2> t = cputime(); sins = sin(angles); cputime()-t
> ans =  0.060991
>
> C (gcc -mtune=native -march=native -O3 benchmark_sin.c -lm
> -lrt):
> CPU time took 0.05 seconds at line number 74 of
> 'benchmark_sin.c' file
> Wallclock time took 0.0486391 seconds at line #74 of
> 'benchmark_sin.c' file
>
> Fortran (gfortran -mtune=native -march=native
> -mfpmath=sse,387 -O2-o
> fs_gf fortran_sin.f90)
> 3.69939999999999991E-002
>
> Fortran (intel: ifort -o fs fortran_sin.f90 -O2):
> 6.000000000000001E-003
>
> Fortran (intel, ifort -o fs fortran_sin.f90 -O2):
> 5.000000000000000E-003
>
> To conclude, on my computer, for this test, Octave is
> approximately
> as fast as C, gfortran is a little bit faster and ifort is
> 10 times as fast.
>
> If you want to speed up your code, write the critical parts
> in Fortran, not C.
>
> Greetings,
>
> Wim
>
>
> $ cat fortran_sin.f90
> program fortran_sin
>   implicit none
>   integer , parameter   :: dp =
> selected_real_kind(p=13,r=300)
>   integer , parameter   :: n  = 1000000
>   integer               :: i
>   real(dp) , parameter  :: pi = 3.1415926535897932385_dp
>   real(dp)              :: angles(n) , sins(n)
>   real(dp)              :: t0 , t1
>
>   call cpu_time(t0)
>   angles = real( [(i, i=0,n-1)]/n , kind=dp )
>   sins   = pi * sin(angles)
>   call cpu_time(t1)
>   print *, t1-t0
>
> end program fortran_sin

I think you should move the

call cpu_time(t0)

line to be just below

angles = real( [(i, i=0,n-1)]/n , kind=dp )

one - to make your program logically equivalent to mine.

I am benchmarking only 'sin' calculations, not calculation of angles in
both 'octave' and "C".

Regards,
  Sergei.


     

_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko
In reply to this post by John W. Eaton



--- On Fri, 1/2/09, John W. Eaton <[hidden email]> wrote:

> From: John W. Eaton <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: "wim van hoydonck" <[hidden email]>
> Cc: [hidden email], [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 2:45 PM
> On  2-Jan-2009, wim van hoydonck wrote:
>
> | To conclude, on my computer, for this test, Octave is
> approximately
> | as fast as C, gfortran is a little bit faster and ifort
> is 10 times as fast.
> |
> | If you want to speed up your code, write the critical
> parts in Fortran, not C.
>
> I don't think that conclusion is justified, but
> whatever.  Clearly it
> is not the language alone, or gfortran would also be 10
> times
> faster...
>
> In any case, I'm surprised by the 10 times factor.  So
> how about
> comparing the assembly code that is generated.  What is
> ifort doing
> that the others are missing?
>
> jwe

Intel compilers are known to very effectively utilize SSE* instructions,
and at all timing/pipelining.

Regards,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko
In reply to this post by John W. Eaton



--- On Fri, 1/2/09, John W. Eaton <[hidden email]> wrote:

> From: John W. Eaton <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: "wim van hoydonck" <[hidden email]>
> Cc: [hidden email], [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 2:45 PM
> On  2-Jan-2009, wim van hoydonck wrote:
>
> | To conclude, on my computer, for this test, Octave is
> approximately
> | as fast as C, gfortran is a little bit faster and ifort
> is 10 times as fast.
> |
> | If you want to speed up your code, write the critical
> parts in Fortran, not C.
>
> I don't think that conclusion is justified, but
> whatever.  Clearly it
> is not the language alone, or gfortran would also be 10
> times
> faster...
>
> In any case, I'm surprised by the 10 times factor.  So
> how about
> comparing the assembly code that is generated.  What is
> ifort doing
> that the others are missing?
>
> jwe

Also, Intel compilers might be using IPPs - Intel Performance Primitives.

FWIW, there is a similar library from AMD, and the license might be more
liberal.

Regards,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko
In reply to this post by wim van hoydonck



--- On Fri, 1/2/09, wim van hoydonck <[hidden email]> wrote:

> From: wim van hoydonck <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "John W. Eaton" <[hidden email]>, [hidden email], "Howard" <[hidden email]>
> Date: Friday, January 2, 2009, 2:21 PM

[snip]

>   sins   = pi * sin(angles)

[snip]

I the above line of code should simply be

sins   = sin(angles)

, i.e. the 'pi' coefficient is wrong.

Thanks,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: compare the executive speed with Matlab

Sergei Steshenko
In reply to this post by wim van hoydonck



--- On Fri, 1/2/09, wim van hoydonck <[hidden email]> wrote:

> From: wim van hoydonck <[hidden email]>
> Subject: Re: compare the executive speed with Matlab
> To: [hidden email]
> Cc: "John W. Eaton" <[hidden email]>, [hidden email], "Howard" <[hidden email]>

[snip]

>   angles = real( [(i, i=0,n-1)]/n , kind=dp )

[snip]

'pi' appears to be missing in the line above, but I'm unfamiliar with
f90 syntax, so I do not know how fix the line, probably

  angles = real( pi * [(i, i=0,n-1)]/n , kind=dp )

Regards,
  Sergei.


     
_______________________________________________
Help-octave mailing list
[hidden email]
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
12