I am using the JMH benchmarking framework (http://openjdk.java.net/projects/code-tools/jmh/) to run benchmarks on my code. My understanding is that JMH forks the JVM multiple times during benchmarking in order to discard any profiles built up by the just-in-time (JIT) profiling performed by the JVM during execution.
I understand why this is useful in some cases such as the below (copied verbatim from http://java-performance.info/jmh/):
By default JHM forks a new java process for each trial (set of iterations). This is required to defend the test from previously collected “profiles” – information about other loaded classes and their execution information. For example, if you have 2 classes implementing the same interface and test the performance of both of them, then the first implementation (in order of testing) is likely to be faster than the second one (in the same JVM), because JIT replaces direct method calls to the first implementation with interface method calls after discovering the second implementation.
However, in the case where you are benchmarking the same code repeatedly is there any advantage to running say 10 forks of 20 iterations each instead of 1 fork with 200 iterations?
Many Thanks,
Danny