-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
performanceMust go fasterMust go fasterregressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous version
Description
Tracked down after performance report on Distances.jl (JuliaStats/Distances.jl#100)
Code to reproduce:
module Distances2
function colwise!(r, a, b)
@inbounds for j = 1:size(a,2)
r[j] = evaluate(view(a, :, j), view(b, :, j))
end
r
end
@inline function evaluate(a, b)
length(a) == 0 && return 0.0 # comment out and 0.7 is super fast
@inbounds begin
s = 0.0
@simd for I in eachindex(a, b)
ai = a[I]
bi = b[I]
s += abs2(ai - bi)
end
return s
end
end
end
using BenchmarkTools
z = zeros(41); A = rand(2, 41); B = rand(2, 41);
@btime Distances2.colwise!($z, $A, $B);
On 0.7:
562.371 ns (82 allocations: 3.84 KiB)
On 0.6:
255.466 ns (0 allocations: 0 bytes)
Now, if we comment away the length(a) == 0 && return 0.0
line:
0.7:
100.298 ns (0 allocations: 0 bytes)
0.6:
206.193 ns (0 allocations: 0 bytes)
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go fasterregressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous version