
Bo Peng wrote:
Dear list,
I am using dynamic_bitset to store a sequence of random 0/1. The program generates repeatedly 32bit random numbers and assign the result to a dynamic_bitset.
for(UINT i=0; i < m_N; ++i) { if(bit == block) // generate a block { ri = rng().randInt(m_max); bit = 0; } if((ri >> bit) & 0x1) succ.set(i); bit++; } When I profile this program, I surprisingly find out that succ.set(i) uses >50% of the execution time. Is there anyway I can assign block by block to dynamic_bitset, or assign sequentially so the position of i does not have to be calculated each time?
Hi,
you code looks very suspect. Are you aware it actually yields m_N bits
rather than m_N blocks? Also, I'll assume the dynamic_bitset is sized in
advance. Sticking to the problem, there are many alternative codings; in
particular you could use the iterator-based version of append, after
creating a little iterator class for the random integers (please, ignore
from_block_range() :-)). If that's not suitable for you might try this:
typedef UINT block_type;
boost::dynamic_bitset