Jeanne Boyarsky wrote:From a design point of view, you should run the code in a loop and measure the average performance of a lot of runs. The reason is that Java optimizes so the first run isn't representative.
I would argue that a large number of the initial iterations should be simply ignored. This way, the just-in-time compiler can do its job, and you won't be measuring the JIT compiler. Also, while not a good idea for applications, it may be needed for benchmarks to force the GC. This way, you won't be measuring the garbage collector too.
Henry