[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 14:48:07 -0800 (PST) |
--- On Fri, 1/2/09, wim van hoydonck <address@hidden> wrote:
> From: wim van hoydonck <address@hidden>
> Subject: Re: compare the executive speed with Matlab
> To: address@hidden
> Cc: "John W. Eaton" <address@hidden>, address@hidden, "Howard"
> <address@hidden>
> Date: Friday, January 2, 2009, 2:21 PM
> On Fri, Jan 2, 2009 at 10:33 PM, Sergei Steshenko
> <address@hidden> wrote:
> >
> >
> >
> > --- On Fri, 1/2/09, John W. Eaton
> <address@hidden> wrote:
> >
> >> From: John W. Eaton <address@hidden>
> >> Subject: Re: compare the executive speed with
> Matlab
> >> To: address@hidden
> >> Cc: "Jordi Guti��rrez Hermoso"
> <address@hidden>, address@hidden,
> "Howard" <address@hidden>
> >> 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.
- Re: compare the executive speed with Matlab, (continued)
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, John W. Eaton, 2009/01/02
- Re: compare the executive speed with Matlab, Jordi Gutiérrez Hermoso, 2009/01/02
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, John W. Eaton, 2009/01/02
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, wim van hoydonck, 2009/01/02
- Re: compare the executive speed with Matlab, John W. Eaton, 2009/01/02
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab,
Sergei Steshenko <=
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, Sergei Steshenko, 2009/01/02
- Re: compare the executive speed with Matlab, wim van hoydonck, 2009/01/05
- Re: compare the executive speed with Matlab, John W. Eaton, 2009/01/02
Re: compare the executive speed with Matlab, Howard, 2009/01/03