Several simple examples are given in $CLASSHG/codes/fortran/optimizing.
See Rotating particles and Fortran efficiency and $CLASSHG/codes/fortran/particles for some other examples.
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.
But there are many sorts of optimizations that the compiler cannot do for you, where some care in coding can make the program run much faster.
- [Goedecker-Hoisie-optimization] contains many techniques for optimizing Fortran codes.