Is if(var == true) faster than if(var != false)?

后端 未结 10 1026
礼貌的吻别
礼貌的吻别 2020-12-18 18:25

Pretty simple question. I know it would probably be a tiny optimization, but eventually you\'ll use enough if statements for it to matter.

EDIT: Thank you to those o

10条回答
  •  旧巷少年郎
    2020-12-18 18:56

    Always optimize for ease of understanding. This is a cardinal rule of programming, as far as I am concerned. You should not micro-optimize, or even optimize at all until you know that you need to do so, and where you need to do so. It's a very rare case that squeezing every ounce of performance out is more important than maintainability and it's even rarer that you're so awesome that you know where to optimize as you initially write the code.

    Furthermore, things like this get automatically optimized out in any decent language.

    tl;dr don't bother

提交回复
热议问题