hi i am building a large application using codeigniter . because the application is very large , performance is a must . i want to optimize my if else statements .
is there is difference of performance using
from
if(false) and if(0)
if(true) and if(1)
what is the efficient way ?
and when using logical operators is their any sequence that optimize the performance
from if((a & b) || c) and if(c || (a & b) )
what is the efficient way ? or those two are the same ?
and from
if(a && b) and if(a & b)
what is the efficient way ?
and from
if(a || b) and if(a | b)
what is the efficient way ?
is there any performance difference between if(a || b) and if((a || b))
note that 2 nd if is in two additional parentheses
please help me ……………………………..
thanks in advance.
This is also known as “micro-optimization”, and generally frowned upon. The difference is hardly measurable at all. If you can shave off 50% of your if “calculation” time (which is a lot for optimization) you will end up with exactly no difference in the end product, unless your code is only if’s and nothing else. Making 1 query, file operation or even a loop/foreach a tiny bit quicker would make more difference. Write your ifs for readability, not for “speed”.
Last but not least: for every performance-based change you need to MEASURE. Do isolated and repeated tests to find out what is quicker.