Tag: switch-statement

49 votes
12 answers
1.4K views
Is 'switch' faster than 'if'?

Is a switch statement actually faster than an if statement? I ran the code below on Visual Studio 2010's

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
63 votes
5 answers
1.7K views
Why does Java switch on contiguous ints appear to run faster with added cases?

I am working on some Java code which needs to be highly optimized as it will run in hot functions that are inv

avatar
Kristopher
0 1 0 9
asked 07 September, 2021