diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..0695beb --- /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: "StableRNGs" + job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..26fba53 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,41 @@ +using FastAlmostBandedMatrices, BenchmarkTools +using StableRNGs, LinearAlgebra + +const SUITE = BenchmarkGroup() +const rng = StableRNG(123) + +# AlmostBandedMatrix = banded part + full "fill" rows at the bottom +n = 300 +m = 4 +banded_part = BandedMatrix(rand(rng, n, n), (3, 2)) +fill_part = rand(rng, m, n) +A = AlmostBandedMatrix(banded_part, fill_part) +x = rand(rng, n) +y = zeros(n) + +A_dense = Matrix(A) + +# ============================================================================= +# Construction +# ============================================================================= + +SUITE["construct"] = BenchmarkGroup() + +SUITE["construct"]["almost_banded"] = @benchmarkable AlmostBandedMatrix( + $banded_part, $fill_part +) +SUITE["construct"]["banded"] = @benchmarkable BandedMatrix( + $(rand(rng, n, n)), (3, 2) +) + +# ============================================================================= +# Operations +# ============================================================================= + +SUITE["ops"] = BenchmarkGroup() + +SUITE["ops"]["matvec"] = @benchmarkable $A * $x +SUITE["ops"]["mul!"] = @benchmarkable mul!($y, $A, $x) +SUITE["ops"]["to_dense"] = @benchmarkable Matrix($A) +SUITE["ops"]["lu"] = @benchmarkable lu($A) +SUITE["ops"]["ldiv"] = @benchmarkable $A_dense \ $x