in reply to Re^2: Interleaving bytes in a string quickly
in thread Interleaving bytes in a string quickly
I had to tweak the 5.6 solution a bit
Why? Your "tweak" made it slower
$ perl -le'$_="abc"; s/(.)/$1\x40/sg; print' a@b@c@ $ perl -le'$_="abc"; s/(?<=.)/\x40/sg; print' a@b@c@ $ perl -le'$_="abc"; s/(?!^)/\x40/sg; print' a@b@c@ $ perl -e' use Benchmark qw( cmpthese ); our $i = chr(1) x 1e6; cmpthese(-3, { cap => sub { (my $o=our $i) =~ s/(.)/$1\x40/sg; }, peek1 => sub { (my $o=our $i) =~ s/(?<=.)/\x40/sg; }, peek2 => sub { (my $o=our $i) =~ s/(?!^)/\x40/sg; }, }); ' Rate cap peek1 peek2 cap 1.39/s -- -25% -27% peek1 1.85/s 33% -- -3% peek2 1.91/s 37% 4% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Interleaving bytes in a string quickly
by BrowserUk (Patriarch) on Feb 26, 2010 at 20:19 UTC |