... And really should be, if you want to use code typed:

# module scope

ff(x::Type{Val{1}}) = 1

const y = 1

function test()
    # local scope
    x = 1
    a = ff(Val{x})
    c = ff(Val{y})
    d = ff(Val{1})
end

@code_warntype test()


Best,
Simon


Am Mittwoch, 16. November 2016 16:06:31 UTC+1 schrieb FANG Colin:
>
> In performance tips, it says
>
> Essentially, Val{T}works only when T is either hard-coded (Val{3}) or 
> already specified in the type-domain.
>
> Suppose I have
>
> ff(::Type{Val{1}}) = 1
>
> I guess the following is on a slower route.
>
> x = 1
> a = ff(::Type{Val{x}})
>
> And maybe this one can be determined in compile time
>
> const y = 1
> a = ff(::Type{Val{y}})
>
> How can I tell if it is fast or slow? @code_warntype doesn't tell the 
> difference here?
>

Reply via email to