Home > Net >  The performance of a single If and multiple If difference
The performance of a single If and multiple If difference

Time:12-16

Statement 1:
if(x!=1 & amp; & X!!!=2) {XXXXXX}
Statement 2:
if(x!=1) {
if(x!=2) {
XXXXXX
}
}
Excuse me one and the performance difference between two sentences, who is big, or is the same,
One thousand IF I and an IF, for example,

CodePudding user response:

If it is the same condition with the switch
If more of course is slow

CodePudding user response:

references between 1/f, refers to the response of the wind:
if it is the same condition with the switch
If more slowly, of course

Combination of multiple conditions

CodePudding user response:

It is better to consider which way is more convenient to read, the performance of this kind of circumstance can be at ease to the compiler optimization,

CodePudding user response:

Did you watch the knew apart,
I suppose, x=1,
So the first
if(x!=1 & amp; & X!!!
=2)Determine the x!=1, direct jumped out the back of the short circuit,

But
if(x!=1) {
if(x!=2) {
Second if will into ah,,,

Of course, I feel the meaning of the original poster is not so,
But the second if indeed in judgment, no matter into not into,

As for how the compiler optimization, I don't know, never dig,

CodePudding user response:

It is not necessary to consider completely legibility
  •  Tags:  
  • C#
  • Related