Off topic: Perhaps single char positive character classes should be optimized to be equivalent to a literal character? Perhaps something can be done about single char negative character classes too.

Update: Corion sent me a message saying he thought this was already done in 5.10, so I put it to the test. Indeed, it is.

Test code used: (Same as OP accept avoided extra sub calls)

#!/usr/bin/perl use strict; use warnings; use Benchmark qw( cmpthese ); our $line = ('a' x 500) . ' ' . ('a' x 20); sub code { "use strict; use warnings; $_[0]; 1;" } cmpthese -2, { literal => code(' our $line =~ / a .{1,10} \ /x; '), class => code(' our $line =~ / a .{1,10} [ ] /x; '), class_nodot => code(' our $line =~ / a [^\n]{1,10} [ ] /smx; '), };
>c:\progs\perl588\bin\perl 674979.pl Rate class_nodot class literal class_nodot 2206/s -- -44% -100% class 3908/s 77% -- -100% literal 805341/s 36409% 20507% -- >c:\progs\perl5100\bin\perl 674979.pl Rate class_nodot literal class class_nodot 618394/s -- -12% -13% literal 704734/s 14% -- -1% class 708360/s 15% 1% --

In reply to Re: The cost of unchecked best practices by ikegami
in thread The cost of unchecked best practices by moritz

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.