I was reviewing old discussions around efficiency and I noticed that summing an array of Bool is still slower (julia-1.3.0-rc5) than summing the same array of values as Int8, which is puzzling since it seems it should involve exactly the same bits and operations.
Is there a reason that this should be so that I’m missing?
julia> using BenchmarkTools
julia> a = rand(Bool, 10000);
julia> b = Int8.(a);
julia> @benchmark sum($a)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 4.188 μs (0.00% GC)
median time: 4.209 μs (0.00% GC)
mean time: 4.466 μs (0.00% GC)
maximum time: 21.049 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 7
julia> @benchmark sum($b)
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 1.766 μs (0.00% GC)
median time: 1.791 μs (0.00% GC)
mean time: 2.005 μs (0.00% GC)
maximum time: 9.272 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 10