This is because you continue to use push_back() , but in fact you already know the size in advance. This means a lot of redundant copying and redistribution. You must first resize it. In addition, you do not need push_back() each value - you must use some form of insert() (I really do not know its exact interface, but I think append() is the name) to insert the entire target vector at once, which should be much better.
In addition, you leave dynamic_bitset as an unsigned long, but as far as I can see, you only insert an unsigned char into it. A change that can make your life easier.
I am also curious what type of codes_ is - if it is map , you can replace it with vector or infact, since it is statically maximum size (256 entries is the maximum unsigned char ), a static array.
Puppy source share