Comparison using ternary operator vs if else vs case switch (Performance)

I searched for if-else vs trernary operator vs switch case, but could not find a message with all three comparisons. However, I came across some good messages and found that the switching register is faster than if-else. You can check below:

Why switch faster than if

Then I came across some messages that said that there is no performance difference between the if-else and the ternary operator. One of the most important messages is the following:

ternary operator versus if statement: question about good condition?

However, I did not find any relevant messages for the switch-case vs trernary statement.

So, I just want to know if I can conclude that the switch case is faster than both ternary operators, and if-else?

I know this is a stupid question, but I want to know the answer.

+4
source share
1 answer

If switch< if-then-elseand if-then-else== ternary, then switch< ternary.

+7
source

Source: https://habr.com/ru/post/1534260/


All Articles