#! perl -slw use strict; use Benchmark qw[ cmpthese ]; sub buk1{ my $s = shift; substr( $s, $_-1, 2 ) =~ m[^(.)\1] and return for @_; return 1; } sub buk2{ my $s = shift; substr $s, $_-1, 1 eq substr $s, $_, 1 and return for @_; return 1; } sub japhy { my $str = shift; my $l = 0; $str =~ ( "^" . join "", map "[01]" x ($_ - ($l+0,$l=$_)[0] - 2) . "(?:01|10)", @_ ); } { my %res=("00"=>0, "01"=>1,"10"=>1,"11"=>0); sub matija{ my $string = shift; my $tmpres=1; foreach (@_) { $tmpres=$tmpres && $res{substr($string,$_-1,2)}; } return $tmpres; } } { vec(my $str, 2, 1) = 1; vec($str, 5, 1) = 1; vec($str, 8, 1) = 1; sub zaxo { my $foo = shift; my $bar = $foo << 1; not ($foo & $str) ^ ($bar & $str); } } sub ysth { (" ".shift) =~ /^@{[map "(?=.{$_}(?:01|10))", @_ ]}/x } our @strings = qw[ 0000000000 1111111111 1010101111 1010101011 ]; our @bitmasks = ( [ 2, 5, 8 ], [ 1, 3, 5, 5, 7 ], [ 2, 4, 7, 8, 10 ] ); cmpthese( -3, { buk1 => q[ for my $string ( @strings ) { buk1 $string, @$_ for @bitmasks } ], buk2 => q[ for my $string ( @strings ) { buk2 $string, @$_ for @bitmasks } ], japhy => q[ for my $string ( @strings ) { japhy $string, @$_ for @bitmasks } ], matija => q[ for my $string ( @strings ) { matija $string, @$_ for @bitmasks } ], # zaxo => q[ # for my $string ( @strings ) { zaxo $string, @$_ for @bitmasks } # ], ysth => q[ for my $string ( @strings ) { ysth $string, @$_ for @bitmasks } ], }); __END__ P:\test>349759 Use of uninitialized value in vec at P:\test\349759.pl line 38. Use of uninitialized value in scalar assignment at P:\test\349759.pl line 38. Rate ysth japhy matija buk1 buk2 ysth 1976/s -- -14% -86% -88% -89% japhy 2289/s 16% -- -84% -86% -87% matija 14241/s 621% 522% -- -16% -19% buk1 16920/s 756% 639% 19% -- -4% buk2 17571/s 789% 668% 23% 4% --