mpptest
in the MPICH distributions contains a more sophisticated
version of this exercise.
One effect that this simple example does not take into account is the behavior of the memory cache. This can lead to an over-estimate of the available performance.