避免 jvm 预热

Avoid jvm warmup(避免 jvm 预热)

本文介绍了避免 jvm 预热的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在设计排序算法测试,我可以这样做以避免 JVM 预热吗?谢谢!

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

推荐答案

JVM预热通常是指JVM找到热点并JIT这些代码段所花费的时间.如果你实际运行几百次(我相信实际上是几千次)测试,你应该会很好.

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.

但是,您应该知道,即使您这样做,也无法保证.您必须对特定的 JVM 进行试验,以确定在重要部分被 JIT 等之前您需要做多少工作.

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.

在这个小案例研究中JIT 编译在 1700 次调用后开始.

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

这篇关于避免 jvm 预热的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:避免 jvm 预热

基础教程推荐