[Numpy-discussion] gfortran/g77+f2py vs gcc+Cython speed comparison

John Travers jtravs@gmail....
Mon Dec 24 08:37:29 CST 2007

On Dec 24, 2007 1:29 PM, Ondrej Certik <ondrej@certik.cz> wrote:
> Hi John,
> > > When using g77 compiler instead of gfortran, I get a speed
> > > up 4.8 times.
> >
> > The difference between g77 and gfortran with version 4.3 is now very
> > small, plus gfortran is going to benefit from all the new
> > vectorisation and optimisation work in gcc. It will not be long before
> > it over takes for good. In addition you can use modern fortran 95/2003
> > code which makes life much easier! In in addition to all that it is
> > very actively maintained and destined to be the default compiler on
> > all linux systems as it is bundled with gcc.
> Yes, I also think gfortran is the way to go, since g77 is dead upstream.
> But currently, the g77 still gives quite a lot faster code than gfortran,
> but I hope it will change.

Yes, I just proved myself wrong (not a rare occurrence...), on my slow laptop:

With gcc (4.3.0 20071223 (experimental)):
real    0m3.272s
user    0m3.120s
sys     0m0.044s

With gfortran (4.3.0 20071223 (experimental)):
real    0m4.294s
user    0m3.976s
sys     0m0.020s

With g77 (3.4.6):
real    0m2.928s
user    0m2.812s
sys     0m0.044s

If g77=1.0 then gcc=1.27 and gfortran=1.41 (far from 4.8 times though!!)

This is in contrast to my recent experiments between gfortran and gcc,
though that code used f95 stuff extensively so was never tested
against g77.

> So your suggestion is to prepare a clean fortran example, that,
> when compiled with gfortran, runs a lot slower, than if compiled with g77?
> Yep, I can do that.

The most interesting will be to compile with g77 and gfortran with the
options to spit out the generated assembler code, then we can see
exactly where the difference is.  I'll dig back in the gfortran
mailing lists and see previous conclusions of the g77 vs gfortran
debate (which occur often). You may just be exercising a particularly
unoptimized part of gfortran.

> So what is your personal opinion about fortran vs C for scientific computing?
> >From the social point of view, I much prefer C, since a lot more people
> know it, but as you say, the good fortran compilers are a lot better, than
> the C compilers. So I don't know. Probably depends on the project and
> a code I want to reuse.

If you haven't guessed I'm pro fortran! My path was C++ -> Matlab ->
Scipy (which I still use for prototyping and short calculations) ->
fortran for big simulations. Of course, the wonderful f2py helps
combining the last two steps!

The turning point came when I discovered modern object orientated
fortran features and particularly the array intrinsics/operations in
fortran 95/2003. I realised that I could code my stuff in almost as
few lines as Matlab and Scipy and also have the fastest execution (if
using commercial compilers). My hope (slightly set back today) is that
gfortran will mature into being as fast/faster than gcc/g77 for most
code. In that case, with gcc on every linux system, then the social
opposition should disappear. Though this still will not help against
people who think f77 is fortran, ignoring the last 30 years of

Anyway, I really must go home now...

More information about the Numpy-discussion mailing list