in reply to Re: Re: Regexp for alphbetical order match within the string
in thread Regexp for alphabetical order match within the string

Just for grins, this tests about 50% quicker than the substr version in your benchmark.

sub is_sorted{ my( $str, $p, $x ) = ( lc shift, 0 ); chop$x lt $x and return 0 while $x = substr $str, $p++, 2; 1; };

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!

Replies are listed 'Best First'.
Re: Regexp for alphbetical order match within the string
by Roy Johnson (Monsignor) on Oct 31, 2003 at 14:47 UTC
    Nice work! On my box, it was about 30% faster, and this subtle tweaking is about 25% faster, yet:
    sub improved { my $lstr = lc shift; my ($p, $ntst) = (length($lstr)-1); chop($ntst = substr($lstr, $p, 2)) lt $ntst and return 0 while ($p--); 1; }
    while this very similar model is actually slower
    sub hobbled { my $str = lc shift; my ($p, $x) = (length($str)-1); chop($x) lt $x and return 0 while $x = substr($str, $p--, 2); 1; }