I can't speak to Julia's branch prediction, but if you rewrite it as 

function f{x}(::Val{x}) ...
...
end

f(Val{True})

then the compiler will create two versions of f, one with the if and one 
without. Then you can @time the results and see if it makes a difference.

On Tuesday, August 2, 2016 at 5:29:41 AM UTC-4, esproff wrote:
>
> So let's say I have a function of the form:
>
> function f(x::Bool)
> for i in 1:10000000
>     *(bunch of stuff)*
>     if x
>         do something
>     end
>     *(even more stuff)*
> end
>
> As you can see I only need to evaluate this if statement once, but instead 
> I'm (in theory) evaluating it millions of times.  How good is Julia's 
> branch prediction?  Does Julia's JIT compiler recognize this and make it so 
> the if statement is only evaluated once?
>

Reply via email to