Is it possible that @keno’s version is only performant on v0.6, but not v0.5?
using BenchmarkTools, StaticArrays
typealias Vec3{T} SVector{3, T}
typealias Mat3{T} SMatrix{3,3,T}
contract1(a, C, b) = Mat3([dot(C[i,:,j,:] * b, a) for i=1:3, j = 1:3])
@eval contract3(a, C, b) = Mat3($(Expr(:tuple, (:(dot(C[$i,:,$j,:] * b, a)) for i=1:3, j=1:3)...)))
a, b = rand(Vec3), rand(Vec3)
C = @SArray rand(3,3,3,3)
(@benchmark contract1($a, $C, $b)) |> display; println()
(@benchmark contract3($a, $C, $b)) |> display; println()
results on v0.6:
julia> (@benchmark contract1($a, $C, $b)) |> display; println()
BenchmarkTools.Trial:
memory estimate: 160 bytes
allocs estimate: 1
--------------
minimum time: 147.303 ns (0.00% GC)
median time: 152.636 ns (0.00% GC)
mean time: 163.265 ns (2.51% GC)
maximum time: 1.335 μs (74.75% GC)
--------------
samples: 10000
evals/sample: 792
julia> (@benchmark contract3($a, $C, $b)) |> display; println()
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 21.301 ns (0.00% GC)
median time: 21.309 ns (0.00% GC)
mean time: 21.806 ns (0.00% GC)
maximum time: 123.591 ns (0.00% GC)
--------------
samples: 10000
evals/sample: 997
Results on v0.5:
julia> (@benchmark contract1($a, $C, $b)) |> display; println()
BenchmarkTools.Trial:
memory estimate: 8.45 KiB
allocs estimate: 28
--------------
minimum time: 1.978 μs (0.00% GC)
median time: 2.043 μs (0.00% GC)
mean time: 2.353 μs (7.15% GC)
maximum time: 83.486 μs (81.14% GC)
--------------
samples: 10000
evals/sample: 10
julia> (@benchmark contract3($a, $C, $b)) |> display; println()
BenchmarkTools.Trial:
memory estimate: 8.30 KiB
allocs estimate: 27
--------------
minimum time: 1.767 μs (0.00% GC)
median time: 1.829 μs (0.00% GC)
mean time: 2.104 μs (7.82% GC)
maximum time: 63.618 μs (92.24% GC)
--------------
samples: 10000
evals/sample: 10