Created
September 10, 2015 16:26
-
-
Save ssfrr/5a104503e0b026702a73 to your computer and use it in GitHub Desktop.
do block vs. begin block in Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dofun(f) = f() | |
macro gendo() | |
ex = Expr(:block) | |
for i in 1:10000 | |
push!(ex.args, :(dofun() do | |
1+$i | |
end)) | |
end | |
ex | |
end | |
function rundo() | |
@gendo | |
end | |
macro genbegin() | |
ex = Expr(:block) | |
for i in 1:10000 | |
push!(ex.args, :(begin | |
1+$i | |
end)) | |
end | |
ex | |
end | |
function runbegin() | |
@genbegin | |
end | |
@time @gendo | |
# 6.942990 seconds (208.73 k allocations: 13.143 MB, 0.13% gc time) | |
# 6.426416 seconds (208.47 k allocations: 13.125 MB, 0.13% gc time) | |
@time @genbegin | |
# 0.001050 seconds (9.49 k allocations: 148.438 KB) | |
# 0.001246 seconds (9.49 k allocations: 148.438 KB) | |
@time rundo() | |
# 76.339691 seconds (1.58 M allocations: 83.071 MB, 0.04% gc time) | |
# 0.001713 seconds (9.49 k allocations: 148.438 KB) | |
@time runbegin() | |
# 0.253740 seconds (1.38 M allocations: 67.851 MB, 8.61% gc time) | |
# 0.000001 seconds (5 allocations: 176 bytes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment