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

    I guess I must have copy&pasted wrong somehow the first time because it didn't work:

    ike5_6 1100110011001100110011001100110011001100 (warning: too few iterations for a reliable count)

    Done correctly this time is does work, but frankly the difference it makes to performance is minimal:

    C:\test>825494 (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate ike5_6 ike510 buk shmem salva jmac lanX fletch ike5_6 0.298/s -- -10% -72% -79% -82% -93% -95% -100% ike510 0.330/s 11% -- -68% -76% -80% -92% -94% -100% buk 1.05/s 251% 217% -- -26% -37% -75% -81% -99% shmem 1.41/s 371% 325% 34% -- -15% -66% -74% -99% salva 1.66/s 457% 402% 59% 18% -- -60% -70% -99% jmac 4.19/s 1305% 1167% 300% 198% 152% -- -24% -97% lanX 5.51/s 1746% 1566% 426% 292% 232% 31% -- -97% fletch 163/s 54408% 49077% 15428% 11461% 9687% 3780% 2852% --

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.