Skip to content

Commit 79f4615

Browse files
committed
bench: add NonLinModel no-allocation tests
1 parent f54c47a commit 79f4615

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

benchmark/benchmarks.jl

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
using BenchmarkTools
22

3-
using ModelPredictiveControl, ControlSystemsBase
3+
using ModelPredictiveControl, ControlSystemsBase, LinearAlgebra
44
Ts = 400.0
55
sys = [ tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]) tf(1.90,[1800.0,1]);
66
tf(-0.74,[800.0,1]) tf(0.74,[800.0,1]) tf(-0.74,[800.0,1]) ]
77
linmodel = setop!(LinModel(sys, Ts, i_d=[3]), uop=[10,50], yop=[50,30], dop=[5])
8+
function f!(ẋ, x, u, d, p)
9+
mul!(ẋ, p.A, x)
10+
mul!(ẋ, p.Bu, u, 1, 1)
11+
mul!(ẋ, p.Bd, d, 1, 1)
12+
return nothing
13+
end
14+
function h!(y, x, d, p)
15+
mul!(y, p.C, x)
16+
mul!(y, p.Dd, d, 1, 1)
17+
return nothing
18+
end
19+
nonlinmodel = NonLinModel(f!, h!, Ts, 2, 4, 2, 1, p=linmodel, solver=nothing)
20+
nonlinmodel = setop!(nonlinmodel, uop=[10,50], yop=[50,30], dop=[5])
821
u, d = [10, 50], [5]
922

1023
const SUITE = BenchmarkGroup()
1124

1225
## ================== SimModel benchmarks =========================================
1326
SUITE["SimModel"]["allocation"] = BenchmarkGroup(["allocation"])
14-
SUITE["SimModel"]["allocation"]["updatestate!"] = @benchmarkable(
27+
SUITE["SimModel"]["allocation"]["LinModel_updatestate"] = @benchmarkable(
1528
updatestate!($linmodel, $u, $d),
1629
samples=1
1730
)
18-
SUITE["SimModel"]["allocation"]["evaloutput"] = @benchmarkable(
31+
SUITE["SimModel"]["allocation"]["LinModel_evaloutput"] = @benchmarkable(
1932
evaloutput($linmodel, $d),
2033
samples=1
2134
)
35+
SUITE["SimModel"]["allocation"]["NonLinModel_updatestate"] = @benchmarkable(
36+
updatestate!($nonlinmodel, $u, $d),
37+
samples=1
38+
)
39+
SUITE["SimModel"]["allocation"]["NonLinModel_evaloutput"] = @benchmarkable(
40+
evaloutput($nonlinmodel, $d),
41+
samples=1
42+
)
2243

2344
## ================== StateEstimator benchmarks ================================
2445

0 commit comments

Comments
 (0)