开发者

Making sure JVM does not optimize [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

how to make sure no jvm and compiler optimization occures

I am trying to compare a bunch of different path finding algorithms all implemented using java, I would like to time these but I need to make sure that JVM does not do any sort o开发者_Go百科f optimization behind my back?


I know what you're thinking -- optimization skews the results if one algorithm can be optimized more efficiently than another. But let me suggest that optimization is part of the answer. If I have two path finding algorithms, and then why wouldn't I favour the one that lends itself to better compiler optimizations in the environment in which it will be executing? Designing an algorithm that optimizes better is part of designing a better algorithm, isn't it?

I know I'm not really answering your question, but I am suggesting that the effects of optimization is part of the timing results you are trying to meaure.


To run your Java program in 100% interpreted mode, you can specify -Xint on your command line. To make the JIT behaive more deterministically, use the -Xbatch flag.

-Xbatch

Disable background compilation. Normally the VM will compile the method as a background task, running the method in interpreter mode until the background compilation is finished. The -Xbatch flag disables background compilation so that compilation of all methods proceeds as a foreground task until completed.

In principal, I agree with Steve J's response above - however - you may wish to collect information on unoptimized code for comparison.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜