Anyone know how to optimize this code much better?
std::bitset<320> bitset1;
//bunch of code here that alters bitset 1 values
//create a subset of bitset 1
std::bitset<240> bitset2;
for(unsigned int s=0; s < 240; s++)
{
bitset2 = bitset1;<br>}<br><br><br>The values 320 and 240 are not specific, just used as an example. Seems a horrible waste of cpu to loop through a bitset 240 times to copy a section of it. Unfortunately if you try and cast it with td::bitset<240> bitset2(bitset1); that doesn't compile.<br><br>Thanks in advance.<br>Stu
Create bitset subset of larger bitset.
As far as I can tell you have three options here.
1. Hope the compiler doesn't generate code that is too slow for that loop in release. It's possible that unrolling it manually 8 times would help there, but I suspect that still wouldn't make it anywhere near as fast as the obvious memcpy() implementation.
2. Make all your bitsets the same size.
3. Implement your own bitset template, with a fast copying function.
1. Hope the compiler doesn't generate code that is too slow for that loop in release. It's possible that unrolling it manually 8 times would help there, but I suspect that still wouldn't make it anywhere near as fast as the obvious memcpy() implementation.
2. Make all your bitsets the same size.
3. Implement your own bitset template, with a fast copying function.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement