Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the benchmark and tests #1

Merged
merged 5 commits into from
Sep 23, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ using StaticArrays
using BenchmarkTools
using Test

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

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

function benchmark_scalar()
probN = NonlinearProblem((u,p) -> u .* u .- 2, 1.0)
sol = @btime (solve($probN, ScalarNewton()))
@test sol * sol - 2 < 1e-9
function benchmark_scalar(f, u0)
probN = NonlinearProblem{false}(f, u0)
sol = (solve(probN, ScalarNewton()))
end

benchmark_immutable()
benchmark_mutable()
benchmark_scalar()
f, u0 = (u,p) -> u .* u .- 2, @SVector[1.0, 1.0]
sf, su0 = (u,p) -> u * u - 2, 1.0
sol = benchmark_immutable(f, u0)
@test all(sol.u .* sol.u .- 2 .< 1e-9)
sol = benchmark_mutable(f, u0)
@test all(sol.u .* sol.u .- 2 .< 1e-9)
sol = benchmark_scalar(sf, su0)
@test sol * sol - 2 < 1e-9

@test_broken (@ballocated benchmark_immutable($f, $u0)) == 0
@test_broken (@ballocated benchmark_mutable($f, $u0)) == 0
@test (@ballocated benchmark_scalar($sf, $su0)) == 0