Skip to content

Slicing Performance #132

@dgiger42

Description

@dgiger42

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions