Welcome! You’re defining a new anonymous function x -> myfn(arg1, arg2, arg3, x)
on every line, which must be compiled, and also requires the compilation of a corresponding method of ForwardDiff.derivative
. To avoid this, wrap a function around the expression you’re benchmarking:
julia> f(y) = ForwardDiff.derivative(x -> myfn(arg1, arg2, arg3, x), y);
julia> @time f(1.0)
Also, arg1
, arg2
and arg3
seem to be global variables, so for performance, make sure they are declared const
.