hi everyone,
I am using julia 1.0.2, and try to precompile for function. precompile() works for function with args(no kwargs), but when have kwargs, it seems not worked, so how to precompile for function with kwargs? my code is this:
function test_kwargs(x::Int; y::Int=2)
num = 1000000
res = zeros(Int, num)
x = Float64(x+y)
for i in 1:num
res[i] = i * x + i * i
end
end
#@time test(2)
precompile(test_kwargs, (Int,))
@time test_kwargs(2)
@time test_kwargs(2)
function test_args(x::Int)
num = 1000000
y = 2
res = zeros(Int, num)
x = Float64(x+y)
for i in 1:num
res[i] = i * x + i * i
end
end
precompile(test_args, (Int,))
@time test_args(2)
@time test_args(2)
output :
0.038996 seconds (16.46 k allocations: 8.472 MiB)
0.009107 seconds (6 allocations: 7.630 MiB)
0.008354 seconds (6 allocations: 7.630 MiB)
0.007994 seconds (6 allocations: 7.630 MiB)