Create quick/reliable benchmark with java?

前端 未结 3 1749
花落未央
花落未央 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:37

    Your code ends up testing mainly garbage collection performance because appending to a String in a loop ends up creating and immediately discarding a large number of increasingly large String objects.

    This is something that inherently leads to wildly varying measurements and is influenced strongy by multi-thread activity.

    I suggest you do something else in your loop that has more predictable performance, like mathematical calculations.

提交回复
热议问题