Push! vs. pushfirst! performance issue with BitArrays

push! seems to have equal speed as pushfirst! for non-bit vectors. In addition, for bit and non-bit vectors push! is equally fast. For bit and non-bit vectors pushfirst! is ~10Kx slower. Does this seem like an issue, or should it be expected?

using BenchmarkTools
bit = BitArray(undef, 10)

int = zeros(Int, 10)

@benchmark push!($bit, true)
@benchmark push!($int, 1)

@benchmark pushfirst!($bit, true)
@benchmark pushfirst!($int,1)

I think this is expected. pushfirst! on BitVector messes with the indexing (since you no longer start indexing at the start of an integer).

1 Like