bitset vs own implementation?

Which would be faster?

1
2
bitset<543> seq;
seq >>= 25;

Or...
1
2
vector<uint64_t> seq (9,0);
seq >>= 25; // imagine the operator is overloaded correctly 


Basically, I'm wondering if bitwise operations and substring extractions on long sequences of 1's and 0's would be faster if you use a vector of unsigned ints rather than a bitset.

Maybe, instead, you can point me to a place that talks about bitset runtime complexity and/or how it's implemented.
Last edited on
A structure with static storage like bitset is not going to be slower than one with dynamic storage, given that the same shifting implementation is used. If anything, you should compare it with array<uint64_t,9>.

// imagine the operator is overloaded correctly

So we're comparing an arbitrary hypothetical implementation with another arbitrary hypothetical implementation?

Implement a shifting function and measure the difference.
It will be about the same, unless the optimizer fails to figure out what your operator >>= does (or unless your library's bitset is particularly badly written.. but most aren't.

For example, GNU bitset's operator>>= begins at line 262 here: http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/std/bitset?view=markup
Topic archived. No new replies allowed.