It appears that setslice_bool is considerably slower than it could be for cases when the slice's step isn't 1. Setting a portion of the bits can be nearly 100x slower than setting all of them, as shown below.
bits = bitarray(10 ** 9)
%timeit bits[:] = True
6 ms ± 184 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
%timeit bits[::2] = True
564 ms ± 1.11 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
While it's not surprising that setting every bit is faster, since that's essentially just a call to memset, it seems like the performance difference is larger than necessary.
In setslice_bool, it calls setbit in a loop, which does bounds checking and other work in every iteration. Perhaps performance could be significantly improved by moving some of the work outside the loop?
It appears that
setslice_boolis considerably slower than it could be for cases when the slice's step isn't 1. Setting a portion of the bits can be nearly 100x slower than setting all of them, as shown below.While it's not surprising that setting every bit is faster, since that's essentially just a call to
memset, it seems like the performance difference is larger than necessary.In
setslice_bool, it callssetbitin a loop, which does bounds checking and other work in every iteration. Perhaps performance could be significantly improved by moving some of the work outside the loop?