You can squeeze out some micro-optimisations. In general, ++$x is slightly faster than $x++; playing with skeeve3_i, I also found that /.../ was faster than /.{3}/ (to an extent that surprised me).

Rate l3epost l3epre l3ipost l3ipre l3epost 42.2/s -- -3% -8% -10% l3epre 43.4/s 3% -- -5% -8% l3ipost 45.8/s 9% 6% -- -3% l3ipre 47.1/s 12% 9% 3% --
is the output from this code:
use strict; use Benchmark qw/ cmpthese /; our $a = "abcdefghij" x 1000; cmpthese(-1, { l3epost => q{ my %a; $a{$1}++ while $a =~ /(?=(.{3}))/g }, l3epre => q{ my %a; ++$a{$1} while $a =~ /(?=(.{3}))/g }, l3ipost => q{ my %a; $a{$1}++ while $a =~ /(?=(...))/g }, l3ipre => q{ my %a; ++$a{$1} while $a =~ /(?=(...))/g }, });

It shouldn't be hard to improve perl to compile $x++ to a preincrement in void context; fixing the regexp engine to make an explicit fixed count as fast as unrolling is likely to be harder.

Update: Now I'm confused: I checked the source, and void postincrement should be getting replaced with preincrement at compile time; I definitely don't understand now why explicit preinc is showing consistently faster times.

Hugo


In reply to Re^2: Question about speeding a regexp count by hv
in thread Question about speeding a regexp count by Commander Salamander

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.