Skip to content

Commit 63b6454

Browse files
committed
bench: add linearize! no-allocation test
1 parent 79f4615 commit 63b6454

File tree

2 files changed

+7
-37
lines changed

2 files changed

+7
-37
lines changed

benchmark/benchmarks.jl

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ const SUITE = BenchmarkGroup()
2424

2525
## ================== SimModel benchmarks =========================================
2626
SUITE["SimModel"]["allocation"] = BenchmarkGroup(["allocation"])
27-
SUITE["SimModel"]["allocation"]["LinModel_updatestate"] = @benchmarkable(
27+
SUITE["SimModel"]["allocation"]["LinModel_updatestate!"] = @benchmarkable(
2828
updatestate!($linmodel, $u, $d),
2929
samples=1
3030
)
3131
SUITE["SimModel"]["allocation"]["LinModel_evaloutput"] = @benchmarkable(
3232
evaloutput($linmodel, $d),
3333
samples=1
3434
)
35-
SUITE["SimModel"]["allocation"]["NonLinModel_updatestate"] = @benchmarkable(
35+
SUITE["SimModel"]["allocation"]["NonLinModel_updatestate!"] = @benchmarkable(
3636
updatestate!($nonlinmodel, $u, $d),
3737
samples=1
3838
)
@@ -41,22 +41,9 @@ SUITE["SimModel"]["allocation"]["NonLinModel_evaloutput"] = @benchmarkable(
4141
samples=1
4242
)
4343

44-
## ================== StateEstimator benchmarks ================================
45-
46-
47-
48-
#=
49-
SUITE["utf8"] = BenchmarkGroup(["string", "unicode"])
50-
teststr = String(join(rand(MersenneTwister(1), 'a':'d', 10^4)))
51-
SUITE["utf8"]["replace"] = @benchmarkable replace($teststr, "a" => "b")
52-
SUITE["utf8"]["join"] = @benchmarkable join($teststr, $teststr)
53-
SUITE["utf8"]["plots"] = BenchmarkGroup()
44+
SUITE["SimModel"]["allocation"]["linearize!"] = @benchmarkable(
45+
linearize!($linmodel, $nonlinmodel),
46+
samples=1
47+
)
5448

55-
SUITE["trigonometry"] = BenchmarkGroup(["math", "triangles"])
56-
SUITE["trigonometry"]["circular"] = BenchmarkGroup()
57-
for f in (sin, cos, tan)
58-
for x in (0.0, pi)
59-
SUITE["trigonometry"]["circular"][string(f), x] = @benchmarkable ($f)($x)
60-
end
61-
end
62-
=#
49+
## ================== StateEstimator benchmarks ================================

test/1_test_sim_model.jl

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,9 @@ end
108108
u, d = [10, 50], Float64[]
109109
@test updatestate!(linmodel1, u) zeros(2)
110110
@test updatestate!(linmodel1, u, d) zeros(2)
111-
@test_skip @allocations(updatestate!(linmodel1, u)) == 0
112111
@test linmodel1.x0 zeros(2)
113112
@test evaloutput(linmodel1) linmodel1() [50,30]
114113
@test evaloutput(linmodel1, Float64[]) linmodel1(Float64[]) [50,30]
115-
@test_skip @allocations(evaloutput(linmodel1)) == 0
116114
x = initstate!(linmodel1, [10, 60])
117115
@test evaloutput(linmodel1) [50 + 19.0, 30 + 7.4]
118116
@test preparestate!(linmodel1) x # new method
@@ -283,11 +281,9 @@ end
283281
u, d = zeros(2), Float64[]
284282
@test updatestate!(nonlinmodel, u) zeros(2)
285283
@test updatestate!(nonlinmodel, u, d) zeros(2)
286-
@test_skip @allocations(updatestate!(nonlinmodel, u)) == 0
287284
@test nonlinmodel.x0 zeros(2)
288285
@test evaloutput(nonlinmodel) nonlinmodel() zeros(2)
289286
@test evaloutput(nonlinmodel, d) nonlinmodel(Float64[]) zeros(2)
290-
@test_skip @allocations(evaloutput(nonlinmodel)) == 0
291287

292288
x = initstate!(nonlinmodel, [0, 10]) # do nothing for NonLinModel
293289
@test evaloutput(nonlinmodel) [0, 0]
@@ -375,19 +371,6 @@ end
375371
h2!(y, x, _, _) = (y .= x)
376372
nonlinmodel4 = NonLinModel(f2!,h2!,Ts,1,1,1,0,solver=nothing,jacobian=AutoFiniteDiff())
377373
@test_nowarn linearize(nonlinmodel4, x=[1], u=[2])
378-
379-
function f3!(xnext, x, u, d, _)
380-
xnext .= x.*u .+ x.*d
381-
end
382-
function h3!(y, x, d, _)
383-
y .= x.*d
384-
end
385-
nonlinmodel4 = NonLinModel(f3!, h3!, Ts, 1, 1, 1, 1, solver=nothing)
386-
linmodel4 = linearize(nonlinmodel4; x, u, d)
387-
# return nothing (see this issue : https://github.com/JuliaLang/julia/issues/51112):
388-
linearize2!(linmodel, model) = (linearize!(linmodel, model); nothing)
389-
linearize2!(linmodel4, nonlinmodel4)
390-
@test_skip @allocations(linearize2!(linmodel4, nonlinmodel4)) == 0
391374
end
392375

393376
@testitem "NonLinModel real time simulations" setup=[SetupMPCtests] begin

0 commit comments

Comments
 (0)