Java speed access array index versus temp variable

前端 未结 6 851
情深已故
情深已故 2021-01-17 13:21

What is faster in Java. Accessing an array index directly multiple times, or saving the value of the array index to a new variable and use this for following compution?

6条回答
  •  温柔的废话
    2021-01-17 14:04

    In the long run declaring a temp array would be quicker because the jvm has to compute the offset when accessing an array element.

    Use a profiling tool and see which is quicker for your use, but I'd caution that unless you're doing something really intensive that is very time-sensitive, this isn't going to be a huge improvement.

提交回复
热议问题