diff --git a/test/big.jl b/test/big.jl index 9c0a5fd..2fb37c5 100644 --- a/test/big.jl +++ b/test/big.jl @@ -5,15 +5,15 @@ # one at http://mozilla.org/MPL/2.0/. function allocation_test( - op, - T, - short, - short_to, - n; + op::F1, + ::Type{T}, + short::F2, + short_to::F3, + n::Integer; a = T(2), b = T(3), c = T(4), -) +) where {T,F1,F2,F3} @test MA.promote_operation(op, T, T) == T alloc_test(() -> MA.promote_operation(op, T, T), 0) if op != div && op != - @@ -45,9 +45,15 @@ end @testset "$T" for T in [BigInt, BigFloat, Rational{BigInt}] MA.Test.int_test(T) @testset "Allocation" begin - allocation_test(+, T, MA.add!!, MA.add_to!!, T <: Rational ? 168 : 0) - allocation_test(-, T, MA.sub!!, MA.sub_to!!, T <: Rational ? 168 : 0) - allocation_test(*, T, MA.mul!!, MA.mul_to!!, T <: Rational ? 240 : 0) + a, b = T(2), T(3) + a + b, a - b, a * b # compilation + # Test that the MA methods have fewer allocated than the Base method + n = T <: Rational ? (@allocated a + b) - 1 : 0 + allocation_test(+, T, MA.add!!, MA.add_to!!, n) + n = T <: Rational ? (@allocated a - b) - 1 : 0 + allocation_test(-, T, MA.sub!!, MA.sub_to!!, n) + n = T <: Rational ? (@allocated a * b) - 1 : 0 + allocation_test(*, T, MA.mul!!, MA.mul_to!!, n) add_sub_mul_test(MA.add_mul, T) add_sub_mul_test(MA.sub_mul, T) if T <: Rational # https://github.com/jump-dev/MutableArithmetics.jl/issues/167 @@ -56,7 +62,7 @@ end T, MA.add!!, MA.add_to!!, - 168, + (@allocated a + b) - 1, a = T(1 // 2), b = T(3 // 2), c = T(5 // 2), @@ -66,7 +72,7 @@ end T, MA.sub!!, MA.sub_to!!, - 168, + (@allocated a - b) - 1, a = T(1 // 2), b = T(3 // 2), c = T(5 // 2), diff --git a/test/broadcast.jl b/test/broadcast.jl index 4124230..cb4de46 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -30,8 +30,8 @@ end @test x == 4 @test y == 5 # FIXME This should not allocate but I couldn't figure out where these - # 240 come from. - alloc_test(() -> MA.broadcast!!(+, a, b), 30 * sizeof(Int)) + # allocations come from. + alloc_test_le(() -> MA.broadcast!!(+, a, b), 336) alloc_test(() -> MA.broadcast!!(+, a, c), 0) end diff --git a/test/utilities.jl b/test/utilities.jl index a153512..efb14ca 100644 --- a/test/utilities.jl +++ b/test/utilities.jl @@ -10,12 +10,12 @@ include("dummy.jl") # Half size on 32-bit. const BIGINT_ALLOC = Sys.WORD_SIZE == 64 ? 48 : 24 -function alloc_test(f, n) +function alloc_test(f::F, n) where {F} f() # compile @test n == @allocated f() end -function alloc_test_le(f, n) +function alloc_test_le(f::F, n) where {F} f() # compile @test n >= @allocated f() end