Branch predictor: How many “if”s are too many?
Couple of thoughts here:<p>&gt; if (debug)<p>The language Elixir, during its compilation phase, actually automatically removes these in the production environment. That is to say, it is a macro which behaves as expected in every environment but &quot;prod&quot;, in which case it removes itself.<p>&gt; conditionals<p>A number of years ago I used Ruby to experiment with writing a version of fizzbuzz that avoided conditionals entirely, and was purely functional:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;pmarreck&#x2F;ruby-snippets&#x2F;blob&#x2F;master&#x2F;functional fizzbuzz without conditionals.rb" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pmarreck&#x2F;ruby-snippets&#x2F;blob&#x2F;master&#x2F;functi...</a><p>(I actually regret using currying here because it hurts the portability of the algorithm)<p>While it may be difficult (if possible) to convert all conditional logic to functional logic in a given algorithm, perhaps a compiler could do the work, if certain patterns emerged.<p>I&#x27;m not a C guy, but I have to wonder if such an algorithm would run faster on Intel or ARM chips by avoiding all branching and branch prediction. Can someone chime in on this?