0

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 of optimization behind my back?

Community
  • 1
  • 1
Hamza Yerlikaya
  • 49,047
  • 44
  • 147
  • 241

2 Answers2

4

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.

Steve J
  • 2,676
  • 20
  • 18
  • The problem is if you're trying to compare the "root" algorithm itself, the optimization may skew the results. IRL, I totally agree, but for research purposes, you'd want to remove as many influences as possible. – Dave Newton Oct 16 '11 at 19:56
0

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.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124