Thank you for really testing that. I didn’t use any benchmark packages but just use practical experience: I execute in my shell (zsh in linux).
The three source code are:
kwarg.jl
import Statistics
import Random
Random.seed!(1)
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s = (
rand(1000) for _ = 1:19
);
function loop_over_global(; a = a, b = b, c = c, d = d, e = e, f = f, g = g, h = h, i = i, j = j, k = k, l = l, m = m, n = n, o = o, p = p, q = q, r = r, s = s)
s0 = -1.797693134862315e308
for vec = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s), ind in vec
s0 += ind
end
return s0
end;
loop_over_global()
tvec = [];
for _ = 1:10000
t = time()
loop_over_global()
push!(tvec, time()-t)
end
println("kwarg_in_def> $(sum(tvec))")
arg.jl
import Statistics
import Random
Random.seed!(1)
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s = (
rand(1000) for _ = 1:19
);
function loop_over_global(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
s0 = -1.797693134862315e308
for vec = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s), ind in vec
s0 += ind
end
return s0
end;
loop_over_global(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
tvec = [];
for _ = 1:10000
t = time()
loop_over_global(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
push!(tvec, time()-t)
end
println("standard_arg> $(sum(tvec))")
const.jl
import Statistics
import Random
Random.seed!(1)
const a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s = (
rand(1000) for _ = 1:19
);
function loop_over_global()
s0 = -1.797693134862315e308
for vec = (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s), ind in vec
s0 += ind
end
return s0
end;
loop_over_global()
tvec = [];
for _ = 1:10000
t = time()
loop_over_global()
push!(tvec, time()-t)
end
println("const_no_arg> $(sum(tvec))")
As you can see, the standard grammar in arg.jl is very cumbersome. The const.jl is both clean and fast.
(One last thing to add, if you drop the const annotation in const.jl, the result is around 18 sec).
Edit: Oh, I see. We can make arg.jl be faster than adding const (I did that in constarg.jl) and get