Which is more expensive multiple conditional branches or multiple relational expression in a single condition?
Posted
by
bman
on Programmers
See other posts from Programmers
or by bman
Published on 2014-05-30T03:42:35Z
Indexed on
2014/05/30
3:50 UTC
Read the original article
Hit count: 133
Performance
|optimization
Which is more expensive in terms of processing costs
if ( x < 20 && z == "M") {
// statements 3
}
if ( x >= 20 && w && x <= 65) {
// statements 1
}
if( x >= 20 &&z != "M"){
// statements 2
}
or this
if ( x < 20 ) {
if( z == 'M') // statements 3;
} else
if ( x <= 65 && w == true ) // statements 1;
if ( z == 'F' ) // statements 2;
}
© Programmers or respective owner