diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..2f82998 --- /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: "SparseArrays,StableRNGs" + job-summary: true diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..0aa7266 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,31 @@ +using SparseMatrixIdentification, BenchmarkTools +using StableRNGs, SparseArrays + +const SUITE = BenchmarkGroup() +const rng = StableRNG(123) + +n = 2000 +A_sparse = sprand(rng, n, n, 0.005) +# Banded sparse matrix +A_band = spdiagm(-1 => rand(rng, n - 1), 0 => rand(rng, n), 2 => rand(rng, n - 2)) +# Block-banded +blk = 50 +A_blk = spdiagm( + -blk => rand(rng, n - blk), 0 => rand(rng, n), blk => rand(rng, n - blk) +) + +# ============================================================================= +# Structure detection +# ============================================================================= + +SUITE["detect"] = BenchmarkGroup() + +SUITE["detect"]["getstructure_sparse"] = @benchmarkable getstructure($A_sparse) +SUITE["detect"]["getstructure_banded"] = @benchmarkable getstructure($A_band) +SUITE["detect"]["getstructure_blockbanded"] = @benchmarkable getstructure($A_blk) +SUITE["detect"]["sparsestructure"] = @benchmarkable sparsestructure( + $A_sparse, 0.5 +) +SUITE["detect"]["sparsestructure_dense"] = @benchmarkable sparsestructure( + $(sparse(rand(rng, 500, 500))), 0.5 +)