In fact, after some modifications (in the input arguments) I found a much higher gain:
function M_to_E(e::Number, M::Number, tol::Number = 1e-10)
# Compute the eccentric anomaly using the Newton-Raphson method.
# ==============================================================
# Make sure that M is in the interval [0,2π].
M = mod(M,2π)
# Initial guess.
#
# See [1, p. 75].
E = (M > π) ? M - e : M + e
sin_E, cos_E = sincos(E)
# Newton-Raphson iterations.
while ( abs(E - e*sin_E - M) > tol )
E = E - (E - e*sin_E - M)/(1-e*cos_E)
sin_E, cos_E = sincos(E)
end
# Return the eccentric anomaly in the interval [0, 2π].
mod(E, 2π)
end
@inline function M_to_Ein(e::Number, M::Number, tol::Number = 1e-10)
# Compute the eccentric anomaly using the Newton-Raphson method.
# ==============================================================
# Make sure that M is in the interval [0,2π].
M = mod(M,2π)
# Initial guess.
#
# See [1, p. 75].
E = (M > π) ? M - e : M + e
sin_E, cos_E = sincos(E)
# Newton-Raphson iterations.
while ( abs(E - e*sin_E - M) > tol )
E = E - (E - e*sin_E - M)/(1-e*cos_E)
sin_E, cos_E = sincos(E)
end
# Return the eccentric anomaly in the interval [0, 2π].
mod(E, 2π)
end
using BenchmarkTools
@btime M_to_E(0.005, 100)
@btime M_to_Ein(0.005, 100)
87.117 ns (0 allocations: 0 bytes)
63.452 ns (0 allocations: 0 bytes)
Should I open an issue or is this expected?