How many runs of Java program do we need to warm

Suppose I have a Java program Test.class . I want to measure its execution time. I wrote a wrapper to do this as below:

class RunTest {

    public static void main(String[] args) {

        long sum = 0;
        int iterations = 20;
        int warmupNum = 10;

        for(int i=0; i<iterations; i++){

            long start = System.nanoTime();
            Test.main(args);
            long end = System.nanoTime();

            if( i > warmupNum )
              sum += end - start;
        }

       System.out.println("ave: "+sum/(iterations-warmupNum));
    }
}

Here how to choose warmupNum , the larger the better? How large is enough? Is this a "standard/common" way to measure Java program's performance?


It is better to use Caliper than creating your own micro-benchmark utility.

How do I write a correct micro-benchmark in Java?

链接地址: http://www.djcxy.com/p/62584.html

上一篇: 如何使用端口80运行PyCharm

下一篇: 我们需要加热多少次Java程序