So the issue here is the y::Any
instead of y::Array{Float64, 1}
and y::Array{Int64, 1}
? Interesting.
julia> function foo(x)
y = fill(Float64(x), 9)
z = fill(Int64(x),10)
z
end
julia> @code_warntype(foo(1))
Variables:
#self#::#foo
x::Int64
y::Array{Float64,1}
z::Array{Int64,1}
Body:
begin
y::Array{Float64,1} = $(Expr(:invoke, LambdaInfo for fill!(::Array{Float64,1}, ::Float64), :(Base.fill!), :((Core.ccall)(:jl_alloc_array_1d,(Core.apply_type)(Core.Array,Float64,1)::Type{Array{Float64,1}},(Core.svec)(Core.Any,Core.Int)::SimpleVector,Array{Float64,1},0,10,0)::Array{Float64,1}), :((Base.box)(Float64,(Base.sitofp)(Float64,x))))) # line 3:
z::Array{Int64,1} = $(Expr(:invoke, LambdaInfo for fill!(::Array{Int64,1}, ::Int64), :(Base.fill!), :((Core.ccall)(:jl_alloc_array_1d,(Core.apply_type)(Core.Array,Int64,1)::Type{Array{Int64,1}},(Core.svec)(Core.Any,Core.Int)::SimpleVector,Array{Int64,1},0,9,0)::Array{Int64,1}), :(x))) # line 4:
return z::Array{Int64,1}
end::Array{Int64,1}
I know this isn’t what I asked about, but here are two extra semirelated pieces of information: 1) the two versions of that function benchmark identically, at about 80ns on my machine; 2) in a nanosecond, light travels just one foot. In the time julia calculates this function, light can only travel from one end of my office building to the other. Sorry for this unrelated information, I just thought it was cool.