Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Benchmark this PR

on:
pull_request:
branches: [master]
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
71 changes: 71 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using MultiScaleArrays, BenchmarkTools
using StableRNGs

const SUITE = BenchmarkGroup()
const rng = StableRNG(123)

# Minimal multi-scale hierarchy: Cell -> Population -> Tissue
struct Cell{B} <: AbstractMultiScaleArrayLeaf{B}
values::Vector{B}
end
struct Population{T <: AbstractMultiScaleArray, B <: Number} <:
AbstractMultiScaleArray{B}
nodes::Vector{T}
values::Vector{B}
end_idxs::Vector{Int}
end
struct Tissue{T <: AbstractMultiScaleArray, B <: Number} <:
AbstractMultiScaleArrayHead{B}
nodes::Vector{T}
values::Vector{B}
end_idxs::Vector{Int}
end

function make_tissue(npops, ncells)
cells = [Cell(rand(rng, 4)) for _ in 1:ncells]
pops = [construct(Population, deepcopy(cells)) for _ in 1:npops]
return construct(Tissue, pops)
end

tissue = make_tissue(10, 20)
tissue_big = make_tissue(50, 40)

# =============================================================================
# Construction
# =============================================================================

SUITE["construct"] = BenchmarkGroup()

cells_small = [Cell(rand(rng, 4)) for _ in 1:20]
pops_small = [construct(Population, deepcopy(cells_small)) for _ in 1:10]

SUITE["construct"]["population"] = @benchmarkable construct(
Population, $(deepcopy(cells_small))
)
SUITE["construct"]["tissue"] = @benchmarkable construct(
Tissue, $(deepcopy(pops_small))
)

# =============================================================================
# Traversal
# =============================================================================

SUITE["iterate"] = BenchmarkGroup()

SUITE["iterate"]["level_iter"] = @benchmarkable collect(level_iter($tissue, 1))
SUITE["iterate"]["level_iter_big"] = @benchmarkable collect(
level_iter($tissue_big, 2)
)
SUITE["iterate"]["eachindex"] = @benchmarkable sum(x -> x, $tissue_big)

# =============================================================================
# Node mutation
# =============================================================================

SUITE["nodes"] = BenchmarkGroup()

SUITE["nodes"]["add_node!"] = @benchmarkable add_node!(t, p) setup = (
t = make_tissue(10, 20);
p = construct(Population, [Cell(rand($rng, 4)) for _ in 1:5])
)
SUITE["nodes"]["num_nodes"] = @benchmarkable num_nodes($tissue_big)
Loading