Closed
Description
In the bitsets module, the bit_count_large()
function is scanning bit by bit with btest()
in the main loop:
bit_count = 0
do block_ = 1_bits_kind, size(self % blocks, kind=bits_kind) - 1
do pos = 0, block_size-1
if ( btest( self % blocks(block_), pos ) ) &
bit_count = bit_count + 1
end do
end do
Using chunks of blocks and the fact that btest()
is elemental, one can get significant performance improvement (on a similar implementation I obtain a 5x speed-up witch a chunk size of 1024):
bit_count = 0
do block_ = 1_bits_kind, size(self % blocks, kind=bits_kind) - 1, chunk
block__ = min(block_+chunk-1,size(self % blocks, kind=bits_kind))
do pos = 0, block_size-1
bit_count = bit_count + count( btest(self % blocks(block_:block__), pos ) )
end do
end do
(edit) of course, this makes sense only for a large number of bits
Metadata
Metadata
Assignees
Labels
No labels