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: [main]
paths-ignore: ['docs/**']

permissions:
pull-requests: write
contents: read

jobs:
benchmark:
runs-on: ubuntu-latest
timeout-minutes: 60
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: "ModelingToolkit,OrdinaryDiffEq"
job-summary: true
47 changes: 47 additions & 0 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using BenchmarkTools
using ModelingToolkit
using ModelingToolkit: t_nounits as t
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Sine
using OrdinaryDiffEq

const SUITE = BenchmarkGroup()

function rc_circuit()
@named source = Sine(offset = 1, amplitude = 10, frequency = 5)
@named voltage = Voltage()
@named resistor = Resistor(R = 1)
@named capacitor = Capacitor(C = 1, v = 0.0)
@named ground = Ground()
@named voltage_sensor = VoltageSensor()
@named current_sensor = CurrentSensor()

connections = [
connect(source.output, voltage.V)
connect(voltage.p, resistor.p)
connect(resistor.n, current_sensor.p)
connect(current_sensor.n, capacitor.p)
connect(capacitor.n, voltage.n, ground.g)
connect(capacitor.p, voltage_sensor.p)
connect(capacitor.n, voltage_sensor.n)
]

return System(
connections, t;
systems = [
resistor, capacitor, source, voltage, ground,
voltage_sensor, current_sensor,
], name = :rc_circuit
)
end

SUITE["rc_circuit"] = BenchmarkGroup()
SUITE["rc_circuit"]["build"] = @benchmarkable rc_circuit()
model = rc_circuit()
SUITE["rc_circuit"]["mtkcompile"] = @benchmarkable mtkcompile($model)
sys = mtkcompile(model)
SUITE["rc_circuit"]["odeproblem"] = @benchmarkable ODEProblem($sys, [], (0.0, 10.0))
prob = ODEProblem(sys, [], (0.0, 10.0))
SUITE["rc_circuit"]["solve"] = @benchmarkable solve(
$prob, Tsit5(); save_everystep = false, abstol = 1.0e-8, reltol = 1.0e-8
)
Loading