Java for loop performance question

前端 未结 13 1185
长发绾君心
长发绾君心 2020-12-15 05:17

considering this example:

public static void main(final String[] args) {
    final List myList = Arrays.asList(\"A\", \"B\", \"C\", \"D\");
            


        
相关标签:
13条回答
  • 2020-12-15 06:00

    Almost certainly what you are seeing here is a difference in HotSpot inlining. With a simpler loop it is more likely to inline, and therefore get rid of all the redundant rubbish. It might do the same inlining, but do it earlier on or with less effort. Generally with Java microbenchmarks you should run the code multiple times, from which you can work out start up times, average times and deviations.

    0 讨论(0)
提交回复
热议问题