Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Closure speeds: Result: 0.5260329246520996 0.656851053237915 0.5118138790130615
begin
local y::Vector{Int64} = zeros(Int64, 1000000)
global demo2
function demo2()
x = y
for ii in 1:1000000
@inbounds x[ii] += 3
end
return x
end
end
begin
local y::Vector{Int64} = zeros(Int64, 1000000)
global demo2slow
function demo2slow()
for ii in 1:1000000
@inbounds y[ii] += 3
end
return y
end
end
bar = zeros(Int64, 1000000)
function demo3(bar)
for ii in 1:1000000
@inbounds bar[ii] += 3
end
return bar
end
start = time()
for i = 1:500
demo2()
end
println(time() - start)
start = time()
for i = 1:500
demo2slow()
end
println(time() - start)
start = time()
for i = 1:500
demo3(bar)
end
println(time() - start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment