+ 1

What is better for checking equality, a switch case or an if else block

1st Nov 2017, 8:23 PM
Christian Parsons
Christian Parsons - avatar
4 Respuestas
+ 4
@Ace That information is incorrect, I'm assuming you also got it from this stack overflow answer, since you basically said the same exact thing. https://stackoverflow.com/questions/767821/is-else-if-faster-than-switch-case While the compiler can make some optimizations with switch statements, it does not implement hashes or lookup tables. Usually jump tables instead, but it is dependent on the compiler, the code, and its optimization settings.
1st Nov 2017, 10:10 PM
aklex
aklex - avatar
+ 1
@Ace So switch is actually faster with 5+ elements? :O
1st Nov 2017, 9:43 PM
LunarCoffee
LunarCoffee - avatar