Skip to content

Instantly share code, notes, and snippets.

@toivoh
Created November 2, 2016 07:38
Show Gist options
  • Save toivoh/b963850d54f66bc5450fc2fc0bc3dddc to your computer and use it in GitHub Desktop.
Save toivoh/b963850d54f66bc5450fc2fc0bc3dddc to your computer and use it in GitHub Desktop.
Julia JIT compiler scaling benchmark
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, 10000, 20000, 30000]
#ns = [10,100, 1000, 2000, 5000, 10000, 20000, 30000, 50000, 100000, 200000]
ts = []
alloced = []
for n in ns
println("-"^79)
@time code = code_big_function(n)
@time data1 = @timed f = eval(code)
@time data2 = @timed code_lowered(f, (Float64,))
@time data3 = @timed f(0.0)
push!(ts, [data1[2], data2[2], data3[2]])
push!(alloced, [data1[3], data2[3], data3[3]])
end
ts, alloced = hcat(ts...), hcat(alloced...)
for (k,p) in enumerate(["e", "l", "c"])
t, a = ts[k,:], alloced[k,:]
display(vcat(["n", "t_$p", "t_$p/n", "t_$p/n^2", "a_$p", "a_$p/n", "a_$p/n^2"]',
hcat(ns, t, t./ns, t./ns.^2, a, a./ns, a./ns.^2)))
println()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment