See Rotating particles and Python efficiency and Rotating particles and Fortran efficiency for some comments on writing programs that run quickly.
See Optimizing Fortran for some simple examples of Fortran optimization.
Compiler such as gfortran can automatically perform some optimizations. The level of optimization is typically denoted by the -O flag, and -O3 is commonly used. See Rotating particles and Fortran efficiency for examples of this in action, including a case where using -O3 makes the code run slower, which can happen.
Note that optimization normally has to be turned off in order to use a debugger on the code, in which case it should be compiled with the -g flag instead to produce more information that can be used by debuggers like gdb.
- [Goedecker-Hoisie-optimization] contains many techniques for optimizing Fortran codes.
- http://en.wikipedia.org/wiki/Compiler_optimization has a good list of the sort of compiler optimizations that might be performed.