|
| 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