If your _usage_ of @map is in the global scope, then it has to compile the expressions each time you use it. That may or may not be a problem for you.
As an alternative that only requires compilation on the first call, try FastAnonymous or NumericFuns. --Tim On Wednesday, March 11, 2015 02:25:10 PM Johan Sigfrids wrote: > I've been playing around with creating a @map macro: > > indexify(s::Symbol, i, syms) = s in syms ? Expr(:ref, s, i) : s > indexify(e::Expr, i, syms) = Expr(e.head, e.args[1], [indexify(a, i, syms) > for a in e.args[2:end]]...) > indexify(a::Any, i, syms) = a > macro map(expr, args...) > quote > @assert all([map(length, ($(args...),))...] .== length($(args[1]))) > out = Array(typeof($(indexify(expr, 1, args))), size($(args[1]))) > for i in 1:length(out) > @inbounds out[i] = $(indexify(expr, :i, args)) > end > out > end > end > > When used inside a function it is nice and fast (around 40x faster than > map), but when used in global scope is is twice as slow as map. I assume > this is because of global variables prevent optimization. Now I wonder if > there is some way to introduce a scope to make the variables in expr local?
