Skip to content

Commit 5d06442

Browse files
Merge pull request #3700 from AayushSabharwal/as/benchmarks
ci: add benchmark CI
2 parents 8906854 + adf6098 commit 5d06442

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

.github/workflows/benchmark.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Benchmark this PR
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
paths-ignore:
7+
- 'docs/**'
8+
9+
permissions:
10+
pull-requests: write # needed to post comments
11+
12+
jobs:
13+
bench:
14+
name: "Benchmarks"
15+
strategy:
16+
matrix:
17+
version:
18+
- "1"
19+
- "lts"
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: MilesCranmer/AirspeedVelocity.jl@action-v1
23+
with:
24+
julia-version: "${{ matrix.version }}"

benchmark/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
3+
OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7"

benchmark/benchmarks.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using ModelingToolkit, BenchmarkTools
2+
using ModelingToolkitStandardLibrary
3+
using ModelingToolkitStandardLibrary.Thermal
4+
using OrdinaryDiffEqDefault
5+
6+
const SUITE = BenchmarkGroup()
7+
8+
@mtkmodel DCMotor begin
9+
@structural_parameters begin
10+
R = 0.5
11+
L = 4.5e-3
12+
k = 0.5
13+
J = 0.02
14+
f = 0.01
15+
V_step = 10
16+
tau_L_step = -3
17+
end
18+
@components begin
19+
ground = Ground()
20+
source = Voltage()
21+
voltage_step = Blocks.Step(height = V_step, start_time = 0)
22+
R1 = Resistor(R = R)
23+
L1 = Inductor(L = L, i = 0.0)
24+
emf = EMF(k = k)
25+
fixed = Fixed()
26+
load = Torque()
27+
load_step = Blocks.Step(height = tau_L_step, start_time = 3)
28+
inertia = Inertia(J = J)
29+
friction = Damper(d = f)
30+
end
31+
@equations begin
32+
connect(fixed.flange, emf.support, friction.flange_b)
33+
connect(emf.flange, friction.flange_a, inertia.flange_a)
34+
connect(inertia.flange_b, load.flange)
35+
connect(load_step.output, load.tau)
36+
connect(voltage_step.output, source.V)
37+
connect(source.p, R1.p)
38+
connect(R1.n, L1.p)
39+
connect(L1.n, emf.p)
40+
connect(emf.n, source.n, ground.g)
41+
end
42+
end
43+
44+
@named model = DCMotor()
45+
46+
SUITE["mtkcompile"] = @benchmarkable mtkcompile($model)
47+
48+
model = mtkcompile(model)
49+
u0 = unknowns(model) .=> 0.0
50+
tspan = (0.0, 6.0)
51+
SUITE["ODEProblem"] = @benchmarkable ODEProblem($model, $u0, $tspan)
52+
53+
prob = ODEProblem(model, u0, tspan)
54+
SUITE["init"] = init($prob)

0 commit comments

Comments
 (0)