+ 1

Does switch statement works faster than else if structure.? or both take the same time?

14th Feb 2016, 3:33 PM
Ru7w1k
Ru7w1k - avatar
10 Réponses
+ 6
It depends on how big the code is and whether you want the script to check each condition because switch statements checks through each condition. While if else stops wherever it finds the condition true. And if you aren't doing some atomic level research or anything of that level I don't think that time difference would even matter
21st Mar 2016, 5:26 AM
Saumya Banthia
Saumya Banthia - avatar
+ 3
both have different way to use and diiferent meathod according to tha condition
13th Jun 2016, 10:17 AM
Iman Ali
Iman Ali - avatar
+ 3
it will take same time
10th Jul 2016, 5:48 AM
Ajit Mhatre
Ajit Mhatre - avatar
+ 2
switch case is a better option if you want to reuse a same function that you need to compare diferent values, in other case if you want to use one time a function only when you find a exclusive value if else structure is a best option for you
14th Jun 2016, 4:55 PM
Alejandro Iturbe
Alejandro Iturbe - avatar
+ 1
if you use if else structure or switch, both are faster. anyone is more faster than the other but switch is better because you can see more easier what do any statement
2nd Mar 2016, 7:03 PM
dalio14
dalio14 - avatar
+ 1
kmmmpkoloilKokomog99
14th Jun 2016, 9:13 PM
Levi Johnson
Levi Johnson - avatar
+ 1
yeah, the execution time of switch is high as compared to else if.Here the readon goes... In else if case, the entire loop had to be traversed to obtain the result, whereas inSwitch it need not save any comparison result to obtain the result. (Also matters Virtual Ram efficiency when doing a Big O notation analysis)
12th Jul 2016, 12:39 PM
Rakesh Krishnan
Rakesh Krishnan - avatar
+ 1
switch is better as it is like the advanced form of nested else statement
19th Jul 2016, 12:41 PM
Jeevan Pokhrel
Jeevan Pokhrel - avatar
+ 1
switch is better as it will work faster then nested if else statement
19th Jul 2016, 12:42 PM
Jeevan Pokhrel
Jeevan Pokhrel - avatar
0
i think they're both taking the same time but swith is easier than if statement.
11th Mar 2016, 12:34 PM
Ismail Essafy
Ismail Essafy - avatar