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 |