Which is faster 'if else if' or 'switch'? test on C++, PHP, PERL, Java, Pascal, JavaScript, Haskell.

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

This was interesting, but in if else if else trees I normally think a lot about what the most common cases of data are expected to be and makes sure those ones require the fewest comparison tests in the way that I write it, i.e. you should only have to check everything relatively rarely. If some of the comparisons are very light and quick and others are heavy, I normally try to put the light ones first, and only do the heavier ones as needed.
I'm still going to watch both videos, but "average number of comparisons to choose a case" can vary wildly depending on how you write it, or at least, in the past it often did for me.

jvsnyc
Автор

pls JVM languages kotlin, scala, java, groovy
and compiled languages comparison Rust, c++, go
also add python to the title for the views

xx
visit shbcf.ru