Executing a vector of expressions: some benchmarks

Don’t work with strings—almost never build expressions using strings. Work with expressions. Like this, for example

genfun_expr(exprs, args...) =
    Expr(:function, Expr(:tuple, args...), Expr(:block, exprs...))

myfunc = eval(genfun_expr(evec, :a))
@btime $myfunc($a)   # 2.863 ns (0 allocations: 0 bytes)
1 Like