Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created May 17, 2017 11:56
Show Gist options
  • Save KristofferC/9db93bfae898c8942d275ca360ab8f62 to your computer and use it in GitHub Desktop.
Save KristofferC/9db93bfae898c8942d275ca360ab8f62 to your computer and use it in GitHub Desktop.
function f1(vs)
z = 0.0
for v in vs
for x in v
z += x
end
end
return z
end
function f2(vs)
z = 0.0
for v in vs
(v -> begin
for x in v
z += x
end
end)(v)
end
return z
end
function f3(vs)
z = 0.0
for v in vs
z += _f3(v)
end
return z
end
function _f3(v)
_z = 0.0
for x in v
_z += x
end
return _z
end
vs = convert(Vector{Any}, [rand(10^5), rand(Int, 10^5), rand(Float32, 10^5)]);
@time f1(vs)
@time f2(vs)
@time f3(vs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment