function codeit(fname, op)
quote
function $fname(n)
s = 0
for i1 = 1:n
s = $op(s, 1)
end
s
end
end
end
eval(codeit(:fsym, :-))
eval(codeit(:ffun, Expr(:quote, -)))
# warm up
fsym(1)
ffun(1)
n = 10_000_000
@time fsym(n)
@time ffun(n)
The second incarnation of the function, ffun, is many orders of magnitude slower than fsym, while the only difference is that it refers to the operation by quoting the - function into the AST, instead of referring to it by name. I'm surprised at this, since I thought that using the name :- would only result in looking up the corresponding function.
The following test code
prints on my machine
The second incarnation of the function,
ffun
, is many orders of magnitude slower thanfsym
, while the only difference is that it refers to the operation by quoting the-
function into the AST, instead of referring to it by name. I'm surprised at this, since I thought that using the name:-
would only result in looking up the corresponding function.