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

后端 未结 10 1030
礼貌的吻别
礼貌的吻别 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:57

    A rule of thumb that usually works is "If you know they do the same thing, then the compiler knows too".

    If the compiler knows that the two forms yield the same result, then it will pick the fastest one.

    Hence, assume that they are equally fast, until your profiler tells you otherwise.

提交回复
热议问题