Create quick/reliable benchmark with java?

前端 未结 3 1748
花落未央
花落未央 2020-11-30 12:18

I\'m trying to create a benchmark test with java. Currently I have the following simple method:

public static long runTest(int times){
    long start = Syste         


        
3条回答
  •  悲&欢浪女
    2020-11-30 12:36

    In the 10 million times run, odds are good the HotSpot compiler detected a "heavily used" piece of code and compiled it into machine native code.

    JVM bytecode is interpreted, which leads it susceptible to more interrupts from other background processes occurring in the JVM (like garbage collection).

    Generally speaking, these kinds of benchmarks are rife with assumptions that don't hold. You cannot believe that a micro benchmark really proves what it set out to prove without a lot of evidence proving that the initial measurement (time) isn't actually measuring your task and possibly some other background tasks. If you don't attempt to control for background tasks, then the measurement is much less useful.

提交回复
热议问题