I have defined a function F that takes a function fas an argument (say F solves for x such that f(x) = 0). The function F calls the function f within large for
loops etc.
I have noticed that there was a large difference in performances (3x) between having f, the first argument of F, as a closure VS a callable object. I thought that, in Julia 0.5, closures were as performant as callable objects. Unfortunately, I cannot find a simple example that reproduces the problem. I think the difference is due to the fact f is not inlined within a call F. Would someone know more? Is there a way to force inlining of f within F
?
This code clarifies the two ways of defining f
:
type Parameters
a::Float64
b::Float64
end
p = Parameters(10.0, 10.0)
# closure
function f(p::Parameters, x)
...
end
F(x -> f(p, x))
# call overloading
function (p::Parameters)(x)
...
end
F(p)
Thanks