Skip to content

Instantly share code, notes, and snippets.

@timholy
Last active March 22, 2017 12:21
Show Gist options
  • Save timholy/c3a963964d12c0c3b5b7c6a34b998a7e to your computer and use it in GitHub Desktop.
Save timholy/c3a963964d12c0c3b5b7c6a34b998a7e to your computer and use it in GitHub Desktop.
barbody = "(a = x+2; b = convert(Float64, a); c = b^2+a; round(Int, c))"
function onemodule(n)
open(joinpath(tempdir(), "A.jl"), "w") do io
println(io, """
__precompile__(true)
module A
""")
for i = 1:n
println(io, """
export foo$i
foo$i(x) = bar$i(x)
@noinline bar$i(x) = $barbody
precompile(foo$i, (Int,))
""")
end
println(io, "end")
end
end
function twomodules(n)
open(joinpath(tempdir(), "B.jl"), "w") do io
println(io, """
__precompile__(true)
module B
using C
""")
for i = 1:n
println(io, """
export foo$i
foo$i(x) = bar$i(x)
precompile(foo$i, (Int,))
""")
end
println(io, "end")
end
open(joinpath(tempdir(), "C.jl"), "w") do io
println(io, """
__precompile__(true)
module C
""")
for i = 1:n
println(io, """
export bar$i
@noinline bar$i(x) = $barbody
""")
end
println(io, "end")
end
end
function testscript(fn, n)
open(fn, "w") do io
print(io, """
function runfoo()
s = 0
""")
for i = 1:n
println(io, " s += foo$i($i)")
end
print(io, """
return s
end
""")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment