I’m a relatively new and now enthusiastic Julia user. While exploring the metaprogramming capabilities I came to the question of this topic. Probably I am missing something or misinterpreting the use intention for
eval, but it looks like there is a big penalty for using them:
julia> @btime Meta.parse("1+1") 36.095 μs (10 allocations: 416 bytes) :(1 + 1) julia> @btime eval(:(1+1)) 66.499 μs (35 allocations: 2.34 KiB) 2 julia> @btime eval(Meta.parse("1+1")) 113.640 μs (43 allocations: 2.61 KiB) 2
Why are these calls so expensive? is there a better way to evaluate an expression represented as a string?