First, and maybe not so surprisingly, I found great performance differences when running the same code on two different machines (up to 6 x faster on one machine).
Then however and very much to my own surprise, running the exactly same code on the same machine on two different days showed great performance differences.
Performance measurement is a surprisingly hard topic and huge differences such as what you observed are very common. There is a lot of known measurement bias such as:
- OS noise, as suggested by DFord's answer
- OS policies (such as scheduler, memory mapper and IO-cache)
- Environment variables, even unused ones
- Memory alignment
- Memory localisation
Each of these parameters may greatly influence the performance of your program. If you want to prepare your program “for high performance” then:
Devise strategies to sanitize environment so that you gain some control over parameters 1-5 above.
Devise tests to determine which combination of parameters do well.
While this is not really the question you asked, I guess you are interested in performance measurement. Here are a few references I suggest to you:
Boehm commenting about execution speed for the same binary
varying by a factor of 2 depending on cache placement
Producing Wrong Data Without Doing Anything Obviously Wrong!
It is very easy to read, contains surprising results, and give a very
good feeling of the difficulty of performance measurement and a few
methods to produce (more) reliable results.
“Stabilizer is a compiler and runtime system that enables statistically
rigorous performance evaluation.” There is a scientific publication
claiming to prove that
gcc are not distinguishable,
you will find plenty of interesting references in there.
As a final word, you just discovered with your measurements that wall clock does not provide a useful information when it comes to measure performance of programs, so that you will never get a useful answer to a question such as “how long runs my program?” and you have to consider more precise statements.