Skip to content

Commit e612b5a

Browse files
authored
Merge pull request #30 from JuliaAstro/benchmark
Add benchmarks
2 parents 6115f3c + e3e95f3 commit e612b5a

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Benchmark PR
2+
on:
3+
pull_request_target:
4+
branches: [main]
5+
permissions:
6+
pull-requests: write # needed to post comments
7+
8+
jobs:
9+
bench:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
julia-version: ["lts", "1", "pre"]
14+
steps:
15+
- uses: MilesCranmer/AirspeedVelocity.jl@action-v1
16+
with:
17+
julia-version: ${{ matrix.julia-version }}
18+
exeflags: "--threads=auto"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
*.jl.*.cov
22
*.jl.cov
33
*.jl.mem
4+
**/*.json
5+
**/*.tmp
46
*.rej
57
.DS_Store
68
.benchmarkci

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.2.3"
44
authors = ["Stefan de Lange"]
55

66
[workspace]
7-
projects = ["test", "docs"]
7+
projects = ["test", "docs", "benchmark", "examples"]
88

99
[deps]
1010
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

benchmark/Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4+
SolarPosition = "5b9d1343-a731-5a90-8730-7bf8d89bf3eb"
5+
6+
[sources]
7+
SolarPosition = { path = ".." }

benchmark/benchmarks.jl

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""
2+
Benchmarks for SolarPosition.jl
3+
4+
Compatible with AirspeedVelocity.jl for benchmarking across package versions.
5+
6+
Run locally with:
7+
benchpkg SolarPosition --rev=main,dirty
8+
9+
Or use the Julia API:
10+
using BenchmarkTools
11+
include("benchmarks/benchmarks.jl")
12+
run(SUITE)
13+
"""
14+
15+
using BenchmarkTools
16+
using SolarPosition
17+
using Dates
18+
19+
# ============================================================================
20+
# Benchmark Suite
21+
# ============================================================================
22+
23+
const SUITE = BenchmarkGroup()
24+
25+
# ============================================================================
26+
# Configuration
27+
# ============================================================================
28+
29+
# Test observer location
30+
const OBSERVER = Observer(51.5074, -0.1278, 11.0) # London
31+
32+
# Standard test datetime
33+
const TEST_DT = DateTime(2024, 6, 21, 12, 0, 0)
34+
35+
# Generate test time vectors of different sizes
36+
function generate_times(n::Int)
37+
return collect(DateTime(2024, 1, 1):Hour(1):(DateTime(2024, 1, 1)+Hour(n-1)))
38+
end
39+
40+
# Available algorithms to benchmark
41+
const POSITION_ALGORITHMS = Dict(
42+
"PSA" => PSA(2020),
43+
"NOAA" => NOAA(),
44+
"Walraven" => Walraven(),
45+
"USNO" => USNO(),
46+
"SPA" => SPA(),
47+
)
48+
49+
const REFRACTION_ALGORITHMS = Dict(
50+
"NoRefraction" => NoRefraction(),
51+
"BENNETT" => BENNETT(),
52+
"ARCHER" => ARCHER(),
53+
"MICHALSKY" => MICHALSKY(),
54+
"SG2" => SG2(),
55+
)
56+
57+
# ============================================================================
58+
# Single Position Benchmarks
59+
# ============================================================================
60+
61+
SUITE["single"] = BenchmarkGroup()
62+
63+
for (name, algo) in POSITION_ALGORITHMS
64+
SUITE["single"][name] = @benchmarkable(solar_position($(OBSERVER), $TEST_DT, $algo))
65+
end
66+
67+
# ============================================================================
68+
# Vector Position Benchmarks (multiple timestamps)
69+
# ============================================================================
70+
71+
SUITE["vector"] = BenchmarkGroup()
72+
73+
for n in [100, 1_000, 10_000, 100_000]
74+
times = generate_times(n)
75+
for (name, algo) in POSITION_ALGORITHMS
76+
SUITE["vector"]["n=$n,$name"] =
77+
@benchmarkable(solar_position($(OBSERVER), $times, $algo))
78+
end
79+
end
80+
81+
# ============================================================================
82+
# Refraction Algorithm Benchmarks
83+
# ============================================================================
84+
85+
SUITE["refraction"] = BenchmarkGroup()
86+
87+
for (name, algo) in REFRACTION_ALGORITHMS
88+
SUITE["refraction"][name] =
89+
@benchmarkable(solar_position($(OBSERVER), $TEST_DT, PSA(), $algo))
90+
end

0 commit comments

Comments
 (0)