in reply to fast bit twiddling
Rate japhy ysth matija zaxo browser +uk2 japhy 8361/s -- -37% -74% -82% - +87% ysth 13309/s 59% -- -58% -71% - +79% matija 31862/s 281% 139% -- -31% - +49% zaxo 46230/s 453% 247% 45% -- - +26% browseruk2 62527/s 648% 370% 96% 35% + --
use strict; use Benchmark qw(:all); cmpthese( 1_000_000, { zaxo => sub { vec(my $str, 2, 1) = 1; vec($str, 5, 1) = 1; vec($str, 8, 1) = 1; my $test = sub { my $foo = shift || $_; my $bar = $foo << 1; not ($foo & $str) ^ ($bar & $str); }; $test->(2); $test->(5); $test->(8); }, japhy => sub { my $str = "1010101011"; my $test = sub { my $l = 0; $str =~ ( "^" . join "", map "[01]" x ($_ - ($l+0,$l=$_)[0] +- 2) . "(?:01|10)", @_ ); }; $test->(2); $test->(5); $test->(8); }, matija => sub { my %res=("00"=>0, "01"=>1,"10"=>1,"11"=>0); my $string = "1010101011"; my $test = sub { my $tmpres=1; foreach (@_) { $tmpres=$tmpres && $res{substr($string,$_-1,2)}; } return $tmpres; }; $test->(2); $test->(5); $test->(8); }, browseruk2 => sub { my $s = "1010101011"; my $test = sub { my $x = shift; substr $s, $x-1, 1 eq substr $s, $x, 1 and return for +@_; return 1; }; $test->(2); $test->(5); $test->(8); }, ysth => sub { my $s = "1010101011"; my $test = sub { (" ".shift) =~ /^@{[map "(?=.{$_}(?:01|1 +0))",@_]}/x }; $test->($s,2); $test->($s,5); $test->($s,8); } });
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: fast bit twiddling
by ysth (Canon) on May 02, 2004 at 10:55 UTC | |
|
Re: Re: fast bit twiddling
by BrowserUk (Patriarch) on May 02, 2004 at 14:03 UTC | |
by exussum0 (Vicar) on May 02, 2004 at 23:47 UTC | |
by BrowserUk (Patriarch) on May 03, 2004 at 06:20 UTC | |
|
Re: Re: fast bit twiddling
by exussum0 (Vicar) on May 02, 2004 at 13:19 UTC |