Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

If I am designing a test on sorting algorithm can I do this way to avoid JVM warmup ? Thank you!

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
339 views
Welcome To Ask or Share your Answers For Others

1 Answer

The JVM warmup usually refers to the time it takes for the JVM to find the hotspots and JIT these sections of the code. If you run your actual tests a few hundred (actually a few thousand I believe) times you should be fairly good to go.

You should however know that, even if you do this, there are no guarantees. You'll have to experiment with your particular JVM to figure out how much work you have to do before the vital parts is JITed and so on.


In this little case study the JIT compilation kicked in after 1700 calls.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...