/((.)\2*)/g does though,
Huh:) How did I missed that?!
... faster (by 12% on my computer).
Only 4% difference on mine under 5.10 or 5.22: ## this 5.10
[0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[
+1 while $s =~ m[((.)\2*)]sg;] };;
Rate a b
a 204/s -- -4%
b 212/s 4% --
[0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[
+1 while $s =~ m[((.)\2*)]sg;] };;
Rate a b
a 204/s -- -4%
b 212/s 4% --
[0]{} Perl>
C:\test>\Perl22\bin\perl.exe \Perl22\bin\p1.pl
[0]{} Perl> $s = join'', map{ chr( 65+rand(26) ) x rand( 100 ) } 1 ..
+1000;;
[0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[
+1 while $s =~ m[((.)\2*)]sg;] };;
Rate a b
a 229/s -- -3%
b 235/s 3% --
[0]{} Perl> cmpthese -1,{a=>q[ 1 while $s =~ m[((?=(.))\2+)]sg;],b=>q[
+1 while $s =~ m[((.)\2*)]sg;] };;
Rate a b
a 229/s -- -4%
b 238/s 4% --
A small, but consistent gain. Thanks.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|