-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Closed
Labels
performanceMust go fasterMust go faster
Description
Consider the following code,
function code_big_function(n::Int)
code = [:( $(symbol("x$k")) = $(symbol("x$(k-1)")) + 1 ) for k=1:n]
quote
let
function f(x0)
$(code...)
return $(symbol("x$n"))
end
end
end
end
@show code_big_function(5)
ns = [10,100, 1000, 2000, 5000]
ts = Float64[]
for n in ns
code = code_big_function(n)
f = eval(code)
data = @timed f(0)
push!(ts, data[2])
end
display(vcat(["n", "t", "t/n", "t/n^2"]',
hcat(ns, ts, ts./ns, ts./ns.^2)))
which creates functions like
function f(x0)
x1 = x0 + 1
x2 = x1 + 1
x3 = x2 + 1
x4 = x3 + 1
x5 = x4 + 1
return x5
end
and records the compilation time as a function of the number of computations n.
The result I got was (with an 81 days old Julia 0.5)
"n" "t" "t/n" "t/n^2"
10.0 0.00408641 0.000408641 4.08641e-5
100.0 0.0340387 0.000340387 3.40387e-6
1000.0 0.779312 0.000779312 7.79312e-7
2000.0 2.5837 0.00129185 6.45926e-7
5000.0 25.0702 0.00501404 1.00281e-6
ie it seems that the compilation time scales at least quadratically with the size of the function. Reducing the amount of optimization with julia -O0 or julia -O1 doesn't seem to help either.
Is there anything that can be done about this?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go faster