I’m seeing poor performance in Boolean dot operators, such as .&
and .!
. Please see below. Any ideas why?
Thanks!
julia> using BenchmarkTools
julia> x, y = rand(Bool,100), rand(Bool,100)
(Bool[false, true, true, true, false, true, true, false, false, true … true, true, true, false, true, false, false, false, false, false], Bool[true, false, true, true, false, false, false, true, true, false … true, false, false, true, false, true, true, true, true, false])
julia> not(v) = [!x for x in v]
not (generic function with 1 method)
julia> and(x,y)=[x[i] && y[i] for i in eachindex(x)]
and (generic function with 1 method)
julia> @benchmark .!x
BenchmarkTools.Trial:
memory estimate: 4.92 KiB
allocs estimate: 19
--------------
minimum time: 4.333 μs (0.00% GC)
median time: 4.889 μs (0.00% GC)
mean time: 5.833 μs (7.18% GC)
maximum time: 340.020 μs (95.77% GC)
--------------
samples: 10000
evals/sample: 7
julia> @benchmark not(x)
BenchmarkTools.Trial:
memory estimate: 208 bytes
allocs estimate: 2
--------------
minimum time: 164.375 ns (0.00% GC)
median time: 167.230 ns (0.00% GC)
mean time: 184.198 ns (2.59% GC)
maximum time: 1.307 μs (74.39% GC)
--------------
samples: 10000
evals/sample: 759
julia> @benchmark x .& y
BenchmarkTools.Trial:
memory estimate: 4.95 KiB
allocs estimate: 20
--------------
minimum time: 4.803 μs (0.00% GC)
median time: 5.271 μs (0.00% GC)
mean time: 6.114 μs (5.39% GC)
maximum time: 331.211 μs (96.50% GC)
--------------
samples: 10000
evals/sample: 7
julia> @benchmark and(x,y)
BenchmarkTools.Trial:
memory estimate: 464 bytes
allocs estimate: 8
--------------
minimum time: 552.909 ns (0.00% GC)
median time: 567.124 ns (0.00% GC)
mean time: 630.907 ns (4.59% GC)
maximum time: 12.199 μs (87.91% GC)
--------------
samples: 10000
evals/sample: 186