You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code below compares a loop over an array vs a loop of the array wrapped in a struct.
struct Foo{T<:Number, A<:AbstractMatrix{T}}
data::AendFoo(data::AbstractMatrix) =Foo{eltype(data), typeof(data)}(data)
functiontest(a, b)
for i in1:length(a.data)
@inbounds a.data[i] = b.data[i]
end
a
endfunctiontest2(a, b)
for i in1:length(a)
@inbounds a[i] = b[i]
end
a
endusing BenchmarkTools
for T in (Float32, Float64, Complex{Float32}, Complex{Float64})
b =rand(T, 128, 128)
a =similar(b)
t_arr = BenchmarkTools.time(minimum(@benchmarktest2($a, $b)))
t_foo = BenchmarkTools.time(minimum(@benchmarktest($(Foo(a)), $(Foo(b)))))
@printf"%s %8.5f μs %8.5f μs\n"lpad(string(T), 16) 10.0^(-3)*t_foo 10.0^(-3)*t_arr
end
On 0.6 this gives (first column is wrapped array):
The code below compares a loop over an array vs a loop of the array wrapped in a struct.
On 0.6 this gives (first column is wrapped array):
so for
Complex{Float64}
it is suddenly slower with the wrapped array.On 0.7:
So on 0.7 this also happens for
Complex{Float32}
which is why I mark this as a regression.Reported at https://discourse.julialang.org/t/slower-indexing-on-custom-type-for-complex-64/5131
The text was updated successfully, but these errors were encountered: