Skip to content

Commit d45be3c

Browse files
committed
Test allocation of both problem initialization and solving
1 parent 5b72760 commit d45be3c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

Project.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1313
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
1414

1515
[extras]
16-
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
1716
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1817

1918
[targets]
20-
test = ["BenchmarkTools", "Test"]
19+
test = ["Test"]

test/runtests.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
using NonlinearSolve
22
using StaticArrays
3-
using BenchmarkTools
43
using Test
54

6-
function benchmark_immutable()
7-
probN = NonlinearProblem((u,p) -> u .* u .- 2, @SVector[1.0, 1.0])
5+
function benchmark_immutable(f, u0)
6+
probN = NonlinearProblem{false}(f, u0)
87
solver = init(probN, NewtonRaphson(), immutable = true, tol = 1e-9)
9-
sol = @btime solve!($solver)
10-
@test all(sol.u .* sol.u .- 2 .< 1e-9)
8+
sol = solve!(solver)
119
end
1210

13-
function benchmark_mutable()
14-
probN = NonlinearProblem((u,p) -> u .* u .- 2, @SVector[1.0, 1.0])
11+
function benchmark_mutable(f, u0)
12+
probN = NonlinearProblem{false}(f, u0)
1513
solver = init(probN, NewtonRaphson(), immutable = false, tol = 1e-9)
16-
sol = @btime (reinit!($solver, $probN); solve!($solver))
17-
@test all(sol.u .* sol.u .- 2 .< 1e-9)
14+
sol = (reinit!(solver, probN); solve!(solver))
1815
end
1916

20-
function benchmark_scalar()
21-
probN = NonlinearProblem((u,p) -> u .* u .- 2, 1.0)
22-
sol = @btime (solve($probN, ScalarNewton()))
23-
@test sol * sol - 2 < 1e-9
17+
function benchmark_scalar(f, u0)
18+
probN = NonlinearProblem{false}(f, u0)
19+
sol = (solve(probN, ScalarNewton()))
2420
end
2521

26-
benchmark_immutable()
27-
benchmark_mutable()
28-
benchmark_scalar()
22+
f, u0 = (u,p) -> u .* u .- 2, @SVector[1.0, 1.0]
23+
sf, su0 = (u,p) -> u * u - 2, 1.0
24+
sol = benchmark_immutable(f, u0)
25+
@test all(sol.u .* sol.u .- 2 .< 1e-9)
26+
sol = benchmark_mutable(f, u0)
27+
@test all(sol.u .* sol.u .- 2 .< 1e-9)
28+
sol = benchmark_scalar(sf, su0)
29+
@test sol * sol - 2 < 1e-9
30+
31+
@allocated benchmark_immutable(f, u0)
32+
@allocated benchmark_mutable(f, u0)
33+
@allocated benchmark_scalar(sf, su0)

0 commit comments

Comments
 (0)