I have three condition to compare. Which one is more faster between the following two? Please point me out. Thanks all!
If var = 1 then
Command for updating database
ElseIf var = 2 then
Command for updating database
ElseIf var = 3 then
Command for updating database
EndIf
and
Select Case var
Case 1
Command for updating database
Case 2
Command for updating database
Case 3
Command for updating database
End Select
If you compile the two fragments and use reflector to disassemble you will see that they both end up as the practically the same IL. The compiler replaces the
if / elsewithcasestatement.This kind of micro optimization is highly unlikely to help you if you have performance problems.
If you have performance problems then you need to profile the program and find out where the bottlenecks are.
If you don’t have performance problems, stop sweating this stuff and worry about writing code that is easily understood.