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

Good point!

I added that test case, as well as a

[ "0", "0", 1],
to test for those pesky perl falsehood values.

buk and buk2 both pass this new test and fail yours. (Edit: Corrected, thanks ysth)

Adding length makes buk2 correct, and doesn't penalize the speed much:

buk2_len                    4610/s                 4007%
buk2                        4791/s                 4168%  

Mike

Replies are listed 'Best First'.
Re^3: Benchmarking "Are all these characters in this sentence?" (Faster still?)
by BrowserUk (Patriarch) on Sep 01, 2008 at 11:43 UTC

    Try it this way. I believe it addresses both the real and conceptual errors and runs even faster:

    buk3 => sub { 1+index $_[0], chop $_[ 1 ] or return for 1 .. length $_[ 1 ]; 1; },

    Who says optimisation can't also result in correct code. Such fun :)


    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.
      You're right - that passes all tests and wins by a good margin.

      You're quite good at this game :)

      I'll update the parent post.


      Mike
Re^3: Benchmarking "Are all these characters in this sentence?"
by ysth (Canon) on Sep 01, 2008 at 16:49 UTC
      Corrected, thanks!

      Mike