0

I have a java process that benchmarks some long running function. But because of cumulative JIT optimizations every next call to the function performs better then previous calls.

Just using -Xint to disable JIT is not an option, because it becomes 10x slower and impossible to benchmark.

  • 1
    You cannot do this. You will need to set up your benchmark some other way -- probably using JMH. – Louis Wasserman Nov 18 '22 at 14:58
  • 1
    Just restart the virtual machine? – Holger Nov 18 '22 at 15:37
  • What are you trying to do? If you want to know how long it takes, why not benchmark that with the optimizations? If you're looking to improve performance, use a Profiler to see where your code spends its time. – Robert Nov 18 '22 at 16:29
  • Can you use the `asm` class to modify the bytecode, call it forcing it to re-JIT, then modify it back to its original? I'd guess that might work. Or change some variable that was previously constant, if it had speculatively inlined / constant-propagated based on that, it would have to redo optimization. But see also [Idiomatic way of performance evaluation?](https://stackoverflow.com/q/60291987) for potential pitfalls of microbenchmarking. – Peter Cordes Nov 18 '22 at 16:42
  • @Robert I want to compare results of running with different parameters. Like for first run alpha =1 and for second run alpha=1.5 and etc. – Temurbek Khujaev Nov 20 '22 at 19:51

0 Answers0