Why is this code with several “or” statements slightly faster than using a lookup table in Java?

后端 未结 5 2416
旧时难觅i
旧时难觅i 2021-02-20 17:30

While looking at a micro-optimization question that I asked yesterday (here), I found something strange: an or statement in Java is running slightly faste

5条回答
  •  天命终不由人
    2021-02-20 17:53

    I would guess that the issues is that range checking for the array and if the array lookup is implemented as a method call. That would certainly overshadow 4 straight int compares. Have you looked at the byte code?

提交回复
热议问题