I needed to shift out the first bit of a bit vector inside a tight loop, so I benchmarked some alternatives. On a short string, the method below was about 8 times faster than looping with vec().
sub shift_vector { my($vector, $length) = @_; return pack "b".($length - 1), substr unpack("b$length", $vector), 1 +; }
|
|---|