Avoid warming up jvm

If I am developing a sort algorithm test, can I do this to avoid the JVM warming up? Thanks!

double count = 0; double start, end; for(int r = 0; r < warmup; r++) { // do test } for(int t = 0; t < runs; t++){ start = System.nanoTime(); // do test end = System.nanoTime(); count += start - end; } double avg = count/avg 
+7
java sorting jvm
source share
4 answers

The JVM warm-up usually refers to the time it takes the JVM to find the hot spots and JITs of these sections of code. If you run your actual tests a few hundred (actually a few thousand, I reckon), you should be pretty good.

However, you should be aware that even if you do, there are no guarantees. You will need to experiment with your specific JVM to find out how much work you need to do before the vital parts are JITed, etc.


In this small case study , JIT compilation began after 1700 calls.

+5
source share

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.

+3
source share

This is a very large area, but here are some tips:

1) make sure that your FULL test (including the iteration loop) is in a routine that is called multiple times. So your test has a for () loop in the "parent" method. push it to the β€œbaby” and call it several times. This allows various JIT technologies to actually perform full optimization without the need to replace code in flight ( dynamic transfer cycle, etc.)

2) Make sure that the test runs are long after AFTER prolonged warm-up. 30s is the minimum minimum for the actual measurement period, after an equally long warm-up, if possible. For example, SPECjbb, etc. It takes several minutes to iterate for several iterations.

+2
source share

Yes. Since the heating cycle starts the actual test, this means that all classes, etc. Will be loaded, and JIT compilations must be started.

0
source share

All Articles