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

Rather than change the tiny operation used to generate a list of letters, just avoid generating a list of letters at all:

sub tye2 { my( $sentence, $wantedLetters )= @_; while( $wantedLetters =~ /(.)/gs ) { return 0 if -1 == index($sentence,$1); } return 1; }

If you want to go for ugly code for the sake of micro-optimizations, then

sub tye1 { my( $sentence, $wantedLetters )= @_; -1 == index($sentence,$1) && return 0 while( $wantedLetters =~ /(.)/gs ); return 1; }

Or get even uglier to the point of risking improper behavior in some cases:

sub tye0 { -1 == index( $_[0], $1 ) && return 0 while( $_[1] =~ /(.)/gs ); return 1; }

- tye        

Replies are listed 'Best First'.
Re^3: Benchmarking "Are all these characters in this sentence?" (/./gs)
by RMGir (Prior) on Aug 30, 2008 at 16:25 UTC
    Very nice!

    Except for the "VeryLong" test case, one of those wins all the other benchmarks. For the short charset cases, tye0 wins, while for the others, tye1 and tye2 are tied :) and slightly better than tye0.

    And on the VeryLong case, repellent's unpack win, but the 2nd place results look like a wash between several of the approaches, and yours are quite competitive.

    I've updated the parent node with your subs, thanks!


    Mike