Hi All,
I have a question about what goes on “under the hood” for these two @benchmark
calls
julia> A = rand([true, false],100); B = rand([true, false],100);
julia> @benchmark C = A .& B
BenchmarkTools.Trial:
memory estimate: 4.36 KiB
allocs estimate: 5
--------------
minimum time: 754.330 ns (0.00% GC)
median time: 1.066 μs (0.00% GC)
mean time: 1.423 μs (29.76% GC)
maximum time: 600.483 μs (99.71% GC)
--------------
samples: 10000
evals/sample: 115
julia> @benchmark (C = similar(A); C .= A .& B)
BenchmarkTools.Trial:
memory estimate: 240 bytes
allocs estimate: 3
--------------
minimum time: 329.578 ns (0.00% GC)
median time: 354.242 ns (0.00% GC)
mean time: 424.331 ns (11.63% GC)
maximum time: 283.793 μs (99.84% GC)
--------------
samples: 10000
evals/sample: 225
Does the second @benchmark
run faster because the pre-allocation step is easy and the .= allows for very quick allocation?