speed: C/C++ vs Fortran 
Author Message
 speed: C/C++ vs Fortran

I suspect this is dealt with somewhere, but I'm sure the argument could always
be updated.

I want fast code. Pure and simple. I need to feed numbers in one end, and do a
large series of calculations, and spit out a few numbers at the other end. I
don't need GUI, graphics, or anything other than raw, un{*filter*}erated speed.

I'm got some code compiled using a decent C compiler, and the same code (in
logic structure at least) using fortran, and the Fortran simply blew past it.
Now I realize that the speed difference is a function of the compiler
implementation to a large (total?) degree, but I was wondering if in general
there was a logical reason, or just a wealth of experience, that would tell me
whether or not Fortran still rules in terms of speed, or if C/C++ is quicker
off the mark.

Flame away... :-)

           _///_                                                              
           -. .-                                                              
           ( L )    \////     +--------------------------------------+        
         --(\=/)--  (   )     |            Evan G. Cooch             |        
        /         \ /  /      |   Department of Biological Sciences  |        
        I          V  /       |        Simon Fraser University       |        
        I            /        |   Burnaby, British Columbia  V5A 1S6 |        

                              +--------------------------------------+        



Mon, 02 Dec 1996 10:57:31 GMT  
 speed: C/C++ vs Fortran

Quote:

>I suspect this is dealt with somewhere, but I'm sure the argument could always
>be updated.
>I want fast code. Pure and simple. I need to feed numbers in one end, and do a
>large series of calculations, and spit out a few numbers at the other end. I
>don't need GUI, graphics, or anything other than raw, un{*filter*}erated speed.
>I'm got some code compiled using a decent C compiler, and the same code (in
>logic structure at least) using Fortran, and the Fortran simply blew past it.
>Now I realize that the speed difference is a function of the compiler
>implementation to a large (total?) degree, but I was wondering if in general
>there was a logical reason, or just a wealth of experience, that would tell me
>whether or not Fortran still rules in terms of speed, or if C/C++ is quicker
>off the mark.
>Flame away... :-)

Evan,

  I've looked into this C++ vs. Fortran speed issue and have found
that on many workstations and supercomputers, it is pretty much a wash
as far as speed (although it is *slightly* more painful in C++ due to
the need to deal with aliasing issues). My experience is that when
there is a huge difference in speed, you're not exactly comparing apples
with apples. I'd be interested in seeing the two sets of code posted.
  You say that all you're concerned about is "raw, un{*filter*}erated speed".
How long does your code take to run? Quite frankly, it's hard to believe
that a long running code would produce "a few numbers" as output. Usually,
the longer a code runs, the more stuff it outputs, and the more important
graphics is for post-processing. In any event, a question that springs
to mind is "How much is *your* time worth?" For many, a language that
helps them reduce the time spent developing programs has worth even if
the execution speed is not the fastest.
  When we write codes, we run the heck out of them for parameter scans, etc.
As a result, we long ago found that that there were strong advantages
to having an interactive code so we could change inputs, perform numerical
experiments, and look at intermediate results. Therefore, languages that
interact well with interpreters and GUIs have some advantages.
  The way you've framed your question, I don't think it particularly matters
what programming language one uses, assuming it can be compiled with a
decent compiler. In this case, the best thing to do is to keep programming
in whatever language you've been using. However, I strongly believe that
your view of scientific codes as being a pipe

   data in -> gurgle, gurgle -> stuff out

is seriously outmoded and certainly applicable to only the smallest codes.
With faster computers, the problems addressed are more complex and finding
languages that help manage this complexity is much more important than it
used to be. I program almost exclusively in C++ and find that it is a good
alternative to Fortran, for me at least. Other people's mileage may vary.

Scott

--
-------------------------------------------------------------------------
Scott W. Haney        || Lawrence Livermore N'Lab || The above views are

(510) 423-6308        || Livermore, CA  94550     || sarily LLNL's.



Tue, 03 Dec 1996 23:43:18 GMT  
 speed: C/C++ vs Fortran

From most of my understanding, the answer is: it depends.  FORTRAN compileres can
usually do more optimizations, especially f77, because of the lack of recursion,
variable aliasing (ignoring POINTER), and other weird operations allowed by C.
Since your problem seems to be one of numbers only, a C compiler with a good
optimizer and the fortran compiler should come out with comparable results.  I
would bet that the FORTRAN version should still be slightly faster, since most of
the computer companies spend more time working on a great f77 instead of a great
cc.  

Remember, if it is calling a bunch of functions, fortran can assume a lot more
than C can about what will happen.  If its strait code, then if both compilers
are of a similar level, then they should operate the same.

Tal Heath



Mon, 16 Dec 1996 21:55:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. to CS: or not to CS: in F-PC assembler

2. Fortran 77 vs Fortran90 vs C vs C++

3. Test and Set (TS) vs Compare and Swap (CS)

4. Cellular automata benchmarks: Java vs C++ vs Java vs C++

5. FORTRAN as First Language for CS Majors?

6. Statistics for maintenance time for C vs C++ vs Fortran

7. Speed of Eiffel vs C++ (was Re: ....)

8. speed of Eiffels vs C++

9. f77 vs c++ execution speed?

10. Python vs. C++ Builder - speed of development

11. fortran vs assembly language: speed

12. Processor speed with Fortran, Ada or C, C++

 

 
Powered by phpBB® Forum Software