These are good answers, but it's quite possible both the Fortran and the C++ versions contain substantial room for speedup, so you wouldn't really expect them to be exactly the same speed now.
Assuming you want either one to be as fast as possible for a given machine and input load, there is a countable infinity of programs that do the job, and some program(s) that take less time than all the others.
What you want to do is remove unnecessary activities until the program approaches that optimal shortness of time, regardless of language.
Here's how I do it, and here's an example of seriously aggressive performance tuning.
If I can just give examples, in C++ (using MFC) here is a case where something you wouldn't normally worry about, array indexing, turns out to cost 40% of the time and can be done better. In an example I did using stl vectors, the cost was even higher.
Similarly in Fortran, I was tuning some code that used the LAPACK library, which one would think would be about as finely optimized as possible.
Chances are it is, for large matrices and a small number of calls.
However, for small matrices and a large number of calls, guess what it was spending a heavy fraction of its time doing.
It was calling a function to do string compares to see what the options were in calling the math functions.
For example, DGEMM is a general routine to do matrix multiplication & scaling.
It's first two arguments are CHARACTER*1 flags that tell it whether either input matrix is transposed.
For small matrices, calling a function to test those flags is a major percent of the time, and could clearly be eliminated by writing a more specialized routine.
The only generality you can draw from these examples is that you need an effective diagnostic (like random-pausing) to tell what the problem is at each stage of performance tuning. The problems you find will undoubtedly be different from these examples, but in every case the only way you know what to fix is to have the program itself tell you.
Once you get rid of the extra stuff being done in the program that exists to make some unspecified general coding easier,
then you can turn the compiler's optimizer loose to do its own level of cycle-squeezing (assuming speed is your major concern).
g++ -O3. I don't know anything about your program, however you also want to make sure that you pass references instead of objects (which invokes the copy constructor) to functions. – Mike Steinert Oct 31 '11 at 20:49