If I am developing a sort algorithm test, can I do this to avoid the JVM warming up?
First pedantry. You should not avoid the JVM workout. It has to happen. What you are trying to do is to prevent the JVM from warming up the test results.
To answer your question, the approach is roughly correct, but it is very difficult to predict how many times you need to complete the test in the initial cycle. It probably depends on the test code, the JVM version, and the JVM settings ... and perhaps, among other things.
What I usually do is simply print out the raw timings, filter out the original βwarm-upsβ of iterations, which seem to have anomalous temporal values βββby eye,β and then calculate the averages manually. This is awkward, but it gives me confidence that I explained the warm-up and other possible sources of the anomalies.
Stephen c
source share