diff --git a/.github/workflows/BenchmarkPRTarget.yml b/.github/workflows/BenchmarkPRTarget.yml new file mode 100644 index 0000000..686c95a --- /dev/null +++ b/.github/workflows/BenchmarkPRTarget.yml @@ -0,0 +1,18 @@ +name: Benchmark PR +on: + pull_request_target: + branches: [main] +permissions: + pull-requests: write # needed to post comments + +jobs: + bench: + runs-on: ubuntu-latest + strategy: + matrix: + julia-version: ["lts", "1", "pre"] + steps: + - uses: MilesCranmer/AirspeedVelocity.jl@action-v1 + with: + julia-version: ${{ matrix.julia-version }} + exeflags: "--threads=auto" diff --git a/.gitignore b/.gitignore index f644b31..43d954f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *.jl.*.cov *.jl.cov *.jl.mem +**/*.json +**/*.tmp *.rej .DS_Store .benchmarkci diff --git a/Project.toml b/Project.toml index 50b3f08..9a48bf3 100644 --- a/Project.toml +++ b/Project.toml @@ -4,7 +4,7 @@ version = "0.2.3" authors = ["Stefan de Lange"] [workspace] -projects = ["test", "docs"] +projects = ["test", "docs", "benchmark", "examples"] [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/benchmark/Project.toml b/benchmark/Project.toml new file mode 100644 index 0000000..181f6aa --- /dev/null +++ b/benchmark/Project.toml @@ -0,0 +1,7 @@ +[deps] +BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +SolarPosition = "5b9d1343-a731-5a90-8730-7bf8d89bf3eb" + +[sources] +SolarPosition = { path = ".." } diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..66d1e12 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,90 @@ +""" +Benchmarks for SolarPosition.jl + +Compatible with AirspeedVelocity.jl for benchmarking across package versions. + +Run locally with: + benchpkg SolarPosition --rev=main,dirty + +Or use the Julia API: + using BenchmarkTools + include("benchmarks/benchmarks.jl") + run(SUITE) +""" + +using BenchmarkTools +using SolarPosition +using Dates + +# ============================================================================ +# Benchmark Suite +# ============================================================================ + +const SUITE = BenchmarkGroup() + +# ============================================================================ +# Configuration +# ============================================================================ + +# Test observer location +const OBSERVER = Observer(51.5074, -0.1278, 11.0) # London + +# Standard test datetime +const TEST_DT = DateTime(2024, 6, 21, 12, 0, 0) + +# Generate test time vectors of different sizes +function generate_times(n::Int) + return collect(DateTime(2024, 1, 1):Hour(1):(DateTime(2024, 1, 1)+Hour(n-1))) +end + +# Available algorithms to benchmark +const POSITION_ALGORITHMS = Dict( + "PSA" => PSA(2020), + "NOAA" => NOAA(), + "Walraven" => Walraven(), + "USNO" => USNO(), + "SPA" => SPA(), +) + +const REFRACTION_ALGORITHMS = Dict( + "NoRefraction" => NoRefraction(), + "BENNETT" => BENNETT(), + "ARCHER" => ARCHER(), + "MICHALSKY" => MICHALSKY(), + "SG2" => SG2(), +) + +# ============================================================================ +# Single Position Benchmarks +# ============================================================================ + +SUITE["single"] = BenchmarkGroup() + +for (name, algo) in POSITION_ALGORITHMS + SUITE["single"][name] = @benchmarkable(solar_position($(OBSERVER), $TEST_DT, $algo)) +end + +# ============================================================================ +# Vector Position Benchmarks (multiple timestamps) +# ============================================================================ + +SUITE["vector"] = BenchmarkGroup() + +for n in [100, 1_000, 10_000, 100_000] + times = generate_times(n) + for (name, algo) in POSITION_ALGORITHMS + SUITE["vector"]["n=$n,$name"] = + @benchmarkable(solar_position($(OBSERVER), $times, $algo)) + end +end + +# ============================================================================ +# Refraction Algorithm Benchmarks +# ============================================================================ + +SUITE["refraction"] = BenchmarkGroup() + +for (name, algo) in REFRACTION_ALGORITHMS + SUITE["refraction"][name] = + @benchmarkable(solar_position($(OBSERVER), $TEST_DT, PSA(), $algo)) +end