in reply to Benchmarking "Are all these characters in this sentence?"

Try this:

buk => sub { my( $s, $w ) = @_; 1+index $s, $_ or return while $_ = chop $w; 1; },

In a cursory test it seems to be about twice as fast as the best of tye's in all cases.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Benchmarking "Are all these characters in this sentence?" (quickest yet?)
  • Download Code

Replies are listed 'Best First'.
Re^2: Benchmarking "Are all these characters in this sentence?" (quickest yet?)
by RMGir (Prior) on Aug 30, 2008 at 20:01 UTC
    This IS fast, but if I run this in my test harness, for some reason it destroys the @testArray contents.

    Aha, found it. $_ isn't localized, so using it that way trashes the array. @#$%@#$.

    buk => sub { my( $s, $w ) = @_; my $c; 1+index $s, $c or return 0 while $c = chop $w; 1; }, works just fine.


    Mike
        I was just updating my other reply to that effect, that's it.

        $_ is a bit scary sometimes, it's auto-scoped so often that it's hard to remember it isn't alway so...


        Mike