Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sincos #9

Merged
merged 1 commit into from
Oct 13, 2017
Merged

Use sincos #9

merged 1 commit into from
Oct 13, 2017

Conversation

giordano
Copy link
Member

In Julia master, where an efficient sincos function is defined, this change should provide a 5-10% speed-up.

Note that TimeIt.jl package doesn't work on Julia master, most probably due to this Julia issue: JuliaLang/julia#23221.

@giordano giordano mentioned this pull request Oct 13, 2017
@giordano
Copy link
Member Author

giordano commented Oct 13, 2017

This is the script I'm using for benchmark (the simple @benchmark macro doesn't currently work on Julia master for the same reason why @timeit is broken):

#!/usr/bin/env julia
using SkyCoords
using BenchmarkTools

io = open("julia_times.csv", "w")
println(io, "n,system,time")
for n in [1, 10, 100, 1000, 10_000, 100_000, 1_000_000]
    println("$n coordinates: ")
    if n == 1
        c = ICRSCoords(2pi*rand(), pi*(rand() - 0.5))
        t1 = minimum(run(tune!(@benchmarkable( convert(GalCoords, $c) ))).times) / 1e9
        println(io, "$n,galactic,$t1")
        t2 = minimum(run(tune!(@benchmarkable( convert(FK5Coords{2000}, $c) ))).times) / 1e9
        println(io, "$n,fk5j2000,$t2")
        t3 = minimum(run(tune!(@benchmarkable( convert(FK5Coords{1975}, $c) ))).times) / 1e9
        println(io, "$n,fk5j1975,$t3")
    else
        c = [ICRSCoords(2pi*rand(), pi*(rand() - 0.5)) for i=1:n]
        t1 = minimum(run(tune!(@benchmarkable( convert(Vector{GalCoords{Float64}}, $c) ))).times) / 1e9
        println(io, "$n,galactic,$t1")
        t2 = minimum(run(tune!(@benchmarkable( convert(Vector{FK5Coords{2000, Float64}}, $c) ))).times) / 1e9
        println(io, "$n,fk5j2000,$t2")
        t3 = minimum(run(tune!(@benchmarkable( convert(Vector{FK5Coords{1975, Float64}}, $c) ))).times) / 1e9
        println(io, "$n,fk5j1975,$t3")
    end
end
close(io)

Result on current master of SkyCoords:

n,system,time
1,galactic,1.0194373673036093e-7
1,fk5j2000,1.7845755395683453e-7
1,fk5j1975,1.8471951219512196e-7
10,galactic,9.211923076923078e-7
10,fk5j2000,9.809333333333332e-7
10,fk5j1975,9.872307692307692e-7
100,galactic,8.904e-6
100,fk5j2000,8.94e-6
100,fk5j1975,8.959666666666667e-6
1000,galactic,0.000111156
1000,fk5j2000,0.000112682
1000,fk5j1975,0.000112151
10000,galactic,0.001142591
10000,fk5j2000,0.00115665
10000,fk5j1975,0.001141865
100000,galactic,0.011440471
100000,fk5j2000,0.011608919
100000,fk5j1975,0.011480269
1000000,galactic,0.115397807
1000000,fk5j2000,0.116892337
1000000,fk5j1975,0.115666098

Result with this PR:

n,system,time
1,galactic,8.347925311203319e-8
1,fk5j2000,1.5674120603015074e-7
1,fk5j1975,1.6583355176933158e-7
10,galactic,8.52828125e-7
10,fk5j2000,9.316551724137931e-7
10,fk5j1975,9.428076923076923e-7
100,galactic,8.383e-6
100,fk5j2000,8.541333333333334e-6
100,fk5j1975,8.529e-6
1000,galactic,0.00010513
1000,fk5j2000,0.00010537
1000,fk5j1975,0.000105959
10000,galactic,0.001079322
10000,fk5j2000,0.001080466
10000,fk5j1975,0.001084719
100000,galactic,0.010842601
100000,fk5j2000,0.010863911
100000,fk5j1975,0.010902358
1000000,galactic,0.10911997
1000000,fk5j2000,0.109268721
1000000,fk5j1975,0.110885803

I ran the benchmarks with Julia master, where the fast sincos is defined. There are performance improvements in the range 4-18%, with the largest improvement for the single element conversion.

@kbarbary
Copy link
Member

Looks good!

@kbarbary kbarbary merged commit ad47548 into JuliaAstro:master Oct 13, 2017
@giordano giordano deleted the sincos branch October 13, 2017 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants