in reply to Re: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)
in thread Challenge: CPU-optimized byte-wise or-equals (for a meter of beer)

This is the in-place version:
Rate split1 substr1 subst subst_i +nplace split1 2.93/s -- -72% -100% + -100% substr1 10.3/s 253% -- -99% + -99% subst 901/s 30682% 8623% -- + -24% subst_inplace 1179/s 40176% 11313% 31% + -- ok 1 ok 2 ok 3 1..3
code:
sub subst_inplace { my ($s1, $s2) = @_; use bytes; $$s1 =~ s/(\0)/substr $s2, $+[0]-1, 1/eg; }

Replies are listed 'Best First'.
Re^3: Challenge: CPU-optimized byte-wise or-equals (for a meter of beer) (copy penalty)
by tye (Sage) on Sep 12, 2007 at 14:46 UTC

    Drop the unneeded capturing parens for a likely boost in speed. Someone should add "use bytes" to ikegami's tr/// version also.

    - tye        

      You're right. I erroneously thought the capture was needed for $-[0] to work. But of course that's not the case.