Re: [algogeeks] switch vs if --> which is faster

2010-11-21 Thread MOHIT ....
switch statement is faster to execute than the if-else-if ladder. This is due to the compiler's ability to optimise the switch statement. In the case of the if-else-if ladder, the code must process each if statement in the order determined by the programmer. However, because each case within a swit

Re: [algogeeks] switch vs if --> which is faster

2010-11-21 Thread MOHIT ....
for switch in the worst case compiler will generate if else chain .. else it uses binary decision tree or jump table for optimization at compile time . -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algog

[algogeeks] switch vs if --> which is faster

2010-11-21 Thread shiva
As per my understanding it is compiler depending thing.. what i feel is switch need to evaluate the expression only once but if else if need to evaluate the expression more than once(what if expression stored in variable and then compare...) Does any one please comment difference in speed of swit