ericagol / NbodyGradient.jl

N-body integrator computes derivatives with respect to initial conditions for TTVs, RV, Photodynamics & more
MIT License
20 stars 9 forks source link

Speeding up computation of sinh(x) and cosh(x) #37

Closed ericagol closed 3 years ago

ericagol commented 3 years ago
giordano commented 3 years ago

Note that in Julia v1.6 sinh and cosh are much faster: https://github.com/JuliaLang/julia/pull/37426

Julia v1.5:

julia> using BenchmarkTools

julia> @btime y .= sinh.(x) setup = (x = randn(1000); y = similar(x));
  22.414 μs (0 allocations: 0 bytes)

julia> @btime y .= cosh.(x) setup = (x = randn(1000); y = similar(x));
  15.094 μs (0 allocations: 0 bytes)

Julia v1.6:

julia> using BenchmarkTools

julia> @btime y .= sinh.(x) setup = (x = randn(1000); y = similar(x));
  8.082 μs (0 allocations: 0 bytes)

julia> @btime y .= cosh.(x) setup = (x = randn(1000); y = similar(x));
  6.833 μs (0 allocations: 0 bytes)
ericagol commented 3 years ago

Thanks, @giordano ! It looks like these are ~twice as fast as the expressions I've written above; nice! Do you know if there is a function like sincos(x), but hyperbolic which computes sinh(x) and cosh(x) simultaneously (with time savings)?

giordano commented 3 years ago

Hehe, I also looked for it. There doesn't seem to be a sincosh, but that'd probably a good addition. Mind opening an issue?

ericagol commented 3 years ago

Leaving this for now.