julia> using BenchmarkTools
julia> function my2outputs(a::Float64, g::F) where {F<:Function}
myRange = LinRange(-10.0,10.0,100)
myMax = -Inf; myx = zero(eltype(myRange));
loga = log(a)
for i ∈ eachindex(myRange)
x = myRange[i]
y = exp(x*loga) / g(x)
newMax = y > myMax
myMax = newMax ? y : myMax
myx = newMax ? x : myx
end
return myMax, myx
end
my2outputs (generic function with 1 method)
julia> function my3outputs(g::F) where {F<:Function}
auxRange = LinRange(1.0,3.0,100)
Vs = Vector{Float64}(undef, 100)
Xs = Vector{Float64}(undef, 100)
for (ind, a) in enumerate(auxRange)
Vs[ind], Xs[ind] = my2outputs(a, g)
end
auxMax, auxLoc = findmax(Vs)
return auxMax, auxRange[auxLoc], Xs[auxLoc]
end
my3outputs (generic function with 1 method)
julia> @btime my3outputs(abs2)
110.051 μs (2 allocations: 1.75 KiB)
(590.4900000000008, 3.0, 10.0)
For some reason, Julia master is around 40% slower than 1.5 when running the above. If I add @inline to my2outputs, it is about 40% faster than Julia 1.5 (which remains the same fast).