diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..87afbc1 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,29 @@ +name: Benchmark this PR + +on: + pull_request: + branches: [main] + paths-ignore: ['docs/**'] + +permissions: + pull-requests: write + contents: read + +jobs: + benchmark: + runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + version: ["1", "lts"] + env: + # Force consistent Julia depot path for self-hosted runners + JULIA_DEPOT_PATH: ~/.julia + steps: + - uses: MilesCranmer/AirspeedVelocity.jl@action-v1 + with: + julia-version: ${{ matrix.version }} + script: "benchmark/benchmarks.jl" + extra-pkgs: "" + job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..74facf5 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,51 @@ +using ADTypes, BenchmarkTools +using SparseArrays + +const SUITE = BenchmarkGroup() + +# ============================================================================= +# Backend construction +# ============================================================================= + +SUITE["construct"] = BenchmarkGroup() + +SUITE["construct"]["AutoForwardDiff"] = @benchmarkable AutoForwardDiff() +SUITE["construct"]["AutoFiniteDiff"] = @benchmarkable AutoFiniteDiff() +SUITE["construct"]["AutoZygote"] = @benchmarkable AutoZygote() +SUITE["construct"]["AutoEnzyme"] = @benchmarkable AutoEnzyme() +SUITE["construct"]["AutoForwardDiff_chunk"] = @benchmarkable AutoForwardDiff( + chunksize = 8 +) +SUITE["construct"]["AutoSparse"] = @benchmarkable AutoSparse(AutoForwardDiff()) + +# ============================================================================= +# Interface queries +# ============================================================================= + +SUITE["interface"] = BenchmarkGroup() + +afd = AutoForwardDiff() +asp = AutoSparse(AutoForwardDiff()) + +SUITE["interface"]["mode"] = @benchmarkable ADTypes.mode($afd) +SUITE["interface"]["dense_ad"] = @benchmarkable ADTypes.dense_ad($asp) +SUITE["interface"]["dense_ad_dense"] = @benchmarkable ADTypes.dense_ad($afd) + +# ============================================================================= +# Sparsity detection (known-pattern path) +# ============================================================================= + +SUITE["sparsity"] = BenchmarkGroup() + +N = 100 +f_jac(x) = x .* x +x_vec = ones(N) +J_pattern = sparse(ones(N, N)) +detector = ADTypes.KnownJacobianSparsityDetector(J_pattern) + +SUITE["sparsity"]["construct_detector"] = @benchmarkable ADTypes.KnownJacobianSparsityDetector( + $J_pattern +) +SUITE["sparsity"]["jacobian_sparsity"] = @benchmarkable jacobian_sparsity( + $f_jac, $x_vec, $detector +)