11using BenchmarkTools
2- using Random
2+ using ModelPredictiveControl, ControlSystemsBase, LinearAlgebra
3+
4+ Ts = 400.0
5+ sys = [ tf (1.90 ,[1800.0 ,1 ]) tf (1.90 ,[1800.0 ,1 ]) tf (1.90 ,[1800.0 ,1 ]);
6+ tf (- 0.74 ,[800.0 ,1 ]) tf (0.74 ,[800.0 ,1 ]) tf (- 0.74 ,[800.0 ,1 ]) ]
37
48const SUITE = BenchmarkGroup ()
59
6- SUITE[" utf8" ] = BenchmarkGroup ([" string" , " unicode" ])
7- teststr = String (join (rand (MersenneTwister (1 ), ' a' :' d' , 10 ^ 4 )))
8- SUITE[" utf8" ][" replace" ] = @benchmarkable replace ($ teststr, " a" => " b" )
9- SUITE[" utf8" ][" join" ] = @benchmarkable join ($ teststr, $ teststr)
10- SUITE[" utf8" ][" plots" ] = BenchmarkGroup ()
11-
12- SUITE[" trigonometry" ] = BenchmarkGroup ([" math" , " triangles" ])
13- SUITE[" trigonometry" ][" circular" ] = BenchmarkGroup ()
14- for f in (sin, cos, tan)
15- for x in (0.0 , pi )
16- SUITE[" trigonometry" ][" circular" ][string (f), x] = @benchmarkable ($ f)($ x)
17- end
10+ # # ==================================================================================
11+ # # ================== SimModel benchmarks ===========================================
12+ # # ==================================================================================
13+ linmodel = setop! (LinModel (sys, Ts, i_d= [3 ]), uop= [10 , 50 ], yop= [50 , 30 ], dop= [5 ])
14+ function f! (ẋ, x, u, d, p)
15+ mul! (ẋ, p. A, x)
16+ mul! (ẋ, p. Bu, u, 1 , 1 )
17+ mul! (ẋ, p. Bd, d, 1 , 1 )
18+ return nothing
19+ end
20+ function h! (y, x, d, p)
21+ mul! (y, p. C, x)
22+ mul! (y, p. Dd, d, 1 , 1 )
23+ return nothing
1824end
25+ nonlinmodel = NonLinModel (f!, h!, Ts, 2 , 4 , 2 , 1 , p= linmodel, solver= nothing )
26+ nonlinmodel = setop! (nonlinmodel, uop= [10 , 50 ], yop= [50 , 30 ], dop= [5 ])
27+ u, d, y = [10 , 50 ], [5 ], [50 , 30 ]
28+
29+ SUITE[" SimModel" ][" allocation" ] = BenchmarkGroup ([" allocation" ])
30+ SUITE[" SimModel" ][" allocation" ][" LinModel_updatestate!" ] = @benchmarkable (
31+ updatestate! ($ linmodel, $ u, $ d),
32+ samples= 1
33+ )
34+ SUITE[" SimModel" ][" allocation" ][" LinModel_evaloutput" ] = @benchmarkable (
35+ evaloutput ($ linmodel, $ d),
36+ samples= 1
37+ )
38+ SUITE[" SimModel" ][" allocation" ][" NonLinModel_updatestate!" ] = @benchmarkable (
39+ updatestate! ($ nonlinmodel, $ u, $ d),
40+ samples= 1
41+ )
42+ SUITE[" SimModel" ][" allocation" ][" NonLinModel_evaloutput" ] = @benchmarkable (
43+ evaloutput ($ nonlinmodel, $ d),
44+ samples= 1
45+ )
46+
47+ SUITE[" SimModel" ][" allocation" ][" NonLinModel_linearize!" ] = @benchmarkable (
48+ linearize! ($ linmodel, $ nonlinmodel),
49+ samples= 1
50+ )
51+
52+ # # ==================================================================================
53+ # # ================== StateEstimator benchmarks =====================================
54+ # # ==================================================================================
55+ skf = SteadyKalmanFilter (linmodel)
56+ SUITE[" StateEstimator" ][" allocation" ] = BenchmarkGroup ([" allocation" ])
57+ SUITE[" StateEstimator" ][" allocation" ][" SteadyKalmanFilter_preparestate!" ] = @benchmarkable (
58+ preparestate! ($ skf, $ y, $ d),
59+ samples= 1
60+ )
61+ SUITE[" StateEstimator" ][" allocation" ][" SteadyKalmanFilter_updatestate!" ] = @benchmarkable (
62+ updatestate! ($ skf, $ u, $ y, $ d),
63+ setup= preparestate! ($ skf, $ y, $ d),
64+ samples= 1
65+ )
66+ SUITE[" StateEstimator" ][" allocation" ][" SteadyKalmanFilter_evaloutput" ] = @benchmarkable (
67+ evaloutput ($ skf, $ d),
68+ setup= preparestate! ($ skf, $ y, $ d),
69+ samples= 1
70+ )
71+
72+ kf = KalmanFilter (linmodel, nint_u= [1 , 1 ], direct= false )
73+ SUITE[" StateEstimator" ][" allocation" ][" KalmanFilter_preparestate!" ] = @benchmarkable (
74+ preparestate! ($ kf, $ y, $ d),
75+ samples= 1
76+ )
77+ SUITE[" StateEstimator" ][" allocation" ][" KalmanFilter_updatestate!" ] = @benchmarkable (
78+ updatestate! ($ kf, $ u, $ y, $ d),
79+ setup= preparestate! ($ kf, $ y, $ d),
80+ samples= 1
81+ )
82+
83+ lo = Luenberger (linmodel, nint_u= [1 , 1 ])
84+ # SUITE["StateEstimator"]["allocation"]["Luenberger_preparestate!"] = @benchmarkable(
85+ # preparestate!($lo, $y, $d),
86+ # samples=1
87+ # )
88+ SUITE[" StateEstimator" ][" allocation" ][" Luenberger_updatestate!" ] = @benchmarkable (
89+ updatestate! ($ lo, $ u, $ y, $ d),
90+ setup= preparestate! ($ lo, $ y, $ d),
91+ samples= 1
92+ )
93+
94+ im = InternalModel (nonlinmodel)
95+ SUITE[" StateEstimator" ][" allocation" ][" InternalModel_preparestate!" ] = @benchmarkable (
96+ preparestate! ($ im, $ y, $ d),
97+ samples= 1
98+ )
99+ SUITE[" StateEstimator" ][" allocation" ][" InternalModel_updatestate!" ] = @benchmarkable (
100+ updatestate! ($ im, $ u, $ y, $ d),
101+ setup= preparestate! ($ im, $ y, $ d),
102+ samples= 1
103+ )
104+
105+ ukf = UnscentedKalmanFilter (nonlinmodel)
106+ SUITE[" StateEstimator" ][" allocation" ][" UnscentedKalmanFilter_preparestate!" ] = @benchmarkable (
107+ preparestate! ($ ukf, $ y, $ d),
108+ samples= 1
109+ )
110+ SUITE[" StateEstimator" ][" allocation" ][" UnscentedKalmanFilter_updatestate!" ] = @benchmarkable (
111+ updatestate! ($ ukf, $ u, $ y, $ d),
112+ setup= preparestate! ($ ukf, $ y, $ d),
113+ samples= 1
114+ )
115+ SUITE[" StateEstimator" ][" allocation" ][" UnscentedKalmanFilter_evaloutput" ] = @benchmarkable (
116+ evaloutput ($ ukf, $ d),
117+ setup= preparestate! ($ ukf, $ y, $ d),
118+ samples= 1
119+ )
120+
121+ ekf = ExtendedKalmanFilter (linmodel, nint_u= [1 , 1 ], direct= false )
122+ SUITE[" StateEstimator" ][" allocation" ][" ExtendedKalmanFilter_preparestate!" ] = @benchmarkable (
123+ preparestate! ($ ekf, $ y, $ d),
124+ samples= 1
125+ )
126+ SUITE[" StateEstimator" ][" allocation" ][" ExtendedKalmanFilter_updatestate!" ] = @benchmarkable (
127+ updatestate! ($ ekf, $ u, $ y, $ d),
128+ setup= preparestate! ($ ekf, $ y, $ d),
129+ samples= 1
130+ )
19131
20- SUITE[" trigonometry" ][" hyperbolic" ] = BenchmarkGroup ()
21- for f in (sin, cos, tan)
22- for x in (0.0 , pi )
23- SUITE[" trigonometry" ][" hyperbolic" ][string (f), x] = @benchmarkable ($ f)($ x)
24- end
25- end
132+ # # ==================================================================================
133+ # # ================== PredictiveController benchmarks ===============================
134+ # # ==================================================================================
135+ empc = ExplicitMPC (linmodel, Mwt= [1 , 1 ], Nwt= [0.1 , 0.1 ], Lwt= [0.1 , 0.1 ])
136+ SUITE[" PredictiveController" ][" allocation" ] = BenchmarkGroup ([" allocation" ])
137+ SUITE[" PredictiveController" ][" allocation" ][" ExplicitMPC_moveinput!" ] = @benchmarkable (
138+ moveinput! ($ empc, $ y, $ d),
139+ setup= preparestate! ($ empc, $ y, $ d),
140+ samples= 1
141+ )
0 commit comments