Is bool check faster than null check?

前端 未结 3 628
暗喜
暗喜 2021-01-18 22:23

E.g. do I need to extract

bool xIsNull = x == null

from the loop where I check x == null?

As I know if (a == tr

3条回答
  •  囚心锁ツ
    2021-01-18 23:03

    Do not concern yourself with microoptimizations. Whichever one is "fastest" will undoubtedly have zero effect on your web app. Use whichever is clearest for you and other programmers to read.

    Unless you have measured and found that there is a problem with your code, and you know exactly where in the code is being slow, you are wasting your time.

    Programmer time is many orders of magnitude more expensive than computer time.

提交回复
热议问题