Skip to content

Commit 4cafaa0

Browse files
Make separate function for allocations test
1 parent 8280c24 commit 4cafaa0

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/basic.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ end
138138
@test ldiv!(op, u) * D) \ v
139139
end
140140

141+
function apply_op!(H, du, u, p, t)
142+
H(du, u, p, t)
143+
return nothing
144+
end
145+
141146
@testset "AddedOperator" begin
142147
A = rand(N, N) |> MatrixOperator
143148
B = rand(N, N) |> MatrixOperator
@@ -187,12 +192,9 @@ end
187192

188193
# Allocations Tests
189194

190-
allocs_tot = @allocations mul!(v, op, u) # warmup
191-
allocs_tot = @allocations mul!(v, op, u)
192-
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
193-
allocs_tot = @allocations mul!(v, op, u, α, β) # warmup
194-
allocs_tot = @allocations mul!(v, op, u, α, β)
195-
@test allocs_tot == 1 # BenchmarkTools.jl returns 0 instead of 1
195+
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0) # warmup
196+
allocs_tot = @allocations apply_op!(op, v, u, (), 1.0)
197+
@test allocs_tot <= 1 # BenchmarkTools.jl returns 0 instead of 1
196198

197199
## Time-Dependent Coefficients
198200

@@ -222,12 +224,12 @@ end
222224
p == 0.1,)
223225
t = 0.1
224226

225-
allocs_sparse = @allocations H_sparse(du, u, p, t) # warmup
226-
allocs_sparse = @allocations H_sparse(du, u, p, t)
227-
allocs_dense = @allocations H_dense(du, u, p, t) # warmup
228-
allocs_dense = @allocations H_dense(du, u, p, t)
229-
@test allocs_sparse == 1 # BenchmarkTools.jl returns 0 instead of 1
230-
@test allocs_dense == 1 # BenchmarkTools.jl returns 0 instead of 1
227+
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t) # warmup
228+
allocs_sparse = @allocations apply_op!(H_sparse, du, u, p, t)
229+
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t) # warmup
230+
allocs_dense = @allocations apply_op!(H_dense, du, u, p, t)
231+
@test allocs_sparse <= 1 # BenchmarkTools.jl returns 0 instead of 1
232+
@test allocs_dense <= 1 # BenchmarkTools.jl returns 0 instead of 1
231233
end
232234
end
233235

0 commit comments

Comments
 (0)