Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Languages faster than C++ [closed]

It is said that Blitz++ provides near-Fortran performance.

Does Fortran actually tend to be faster than regular C++ for equivalent tasks?

What about other HL languages of exceptional runtime performance? I've heard of a few languages suprassing C++ for certain tasks... Objective Caml, Java, D...

I guess GC can make much code faster, because it removes the need for excessive copying around the stack? (assuming the code is not written for performance)

I am asking out of curiosity -- I always assumed C++ is pretty much unbeatable barring expert ASM coding.


2 Answers

Fortran is faster and almost always better than C++ for purely numerical code. There are many reasons why Fortran is faster. It is the oldest compiled language (a lot of knowledge in optimizing compilers). It is still THE language for numerical computations, so many compiler vendors make a living of selling optimized compilers. There are also other, more technical reasons. Fortran (well, at least Fortran77) does not have pointers, and thus, does not have the aliasing problems, which plague the C/C++ languages in that domain. Many high performance libraries are still coded in Fortran, with a long (> 30 years) history. Neither C or C++ have any good array constructs (C is too low level, C++ has as many array libraries as compilers on the planet, which are all incompatible with each other, thus preventing a pool of well tested, fast code).

like image 170
David Cournapeau Avatar answered Sep 12 '25 15:09

David Cournapeau


Whether fortran is faster than c++ is a matter of discussion. Some say yes, some say no; I won't go into that. It depends on the compiler, the architecture you're running it on, the implementation of the algorithm ... etc.

Where fortran does have a big advantage over C is the time it takes you to implement those algorithms. And that makes it extremely well suited for any kind of numerical computing. I'll state just a few obvious advantages over C:

  • 1-based array indexing (tremendously helpful when implementing larger models, and you don't have to think about it, but just FORmula TRANslate
  • has a power operator (**) (God, whose idea was that a power function will do ? Instead of an operator?!)
  • it has, I'd say the best support for multidimensional arrays of all the languages in the current market (and it doesn't seem that's gonna change so soon) - A(1,2) just like in math
  • not to mention avoiding the loops - A=B*C multiplies the arrays (almost like matlab syntax with compiled speed)
  • it has parallelism features built into the language (check the new standard on this one)
  • very easily connectible with languages like C, python, so you can make your heavy duty calculations in fortran, while .. whatever ... in the language of your choice, if you feel so inclined
  • completely backward compatible (since whole F77 is a subset of F90) so you have whole century of coding at your disposal
  • very very portable (this might not work for some compiler extensions, but in general it works like a charm)
  • problem oriented solving community (since fortran users are usually not cs, but math, phy, engineers ... people with no programming, but rather problem solving experience whose knowledge about your problem can be very helpful)

Can't think of anything else off the top of my head right now, so this will have to do.

like image 32
Rook Avatar answered Sep 12 '25 15:09

Rook