Efficiency of Java code with primitive types

前端 未结 9 763
遥遥无期
遥遥无期 2021-01-03 12:18

I want to ask which piece of code is more efficient in Java? Code 1:

void f()
{
 for(int i = 0 ; i < 99999;i++)
 {
  for(int j = 0 ; j < 99999;j++)
  {         


        
9条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 12:34

    IT. DOESN'T. MAKE. A. DIFFERENCE.

    Stop micro-optimizing. These little tricks don't make programs run much faster.

    Concentrate on big picture optimizations and writing readable code.

    Declare variables where they make sense, and where it helps understanding the semantics of the overall code in the bigger context, not because you think it's faster one place over another.

提交回复
热议问题