scott-griffiths / bitstring

A Python module to help you manage your bits
https://bitstring.readthedocs.io/en/stable/index.html
MIT License
404 stars 68 forks source link

count method unreasonably slow? #234

Closed scott-griffiths closed 2 years ago

scott-griffiths commented 2 years ago
s = bitstring.BitArray(100000000)
s.set(1, [4, 44, 4444444])

s.count(1) takes about 4 seconds whereas

len(list(s.findall('0b1')))

is at least 10x faster. Count should be at least as fast as find!

scott-griffiths commented 2 years ago

This might be an edge case for very sparse bitstrings. If I count zeros instead then the count time stays the same but the find time is horrendous!