$ perl -MBench -e'$s = "a b"; /(\w+) (\w+)/; bench sub {$a=$1; $b=$2}, + -1' 3666664 calls (3339959/s), 1.098s (0.0003ms/call) $ perl -MBench -e'$s = "a b"; /(?<a>\w+) (?<a>\w+)/; bench sub {$a=$+{ +a}; $b=$+{b}}, -1' 636364 calls (560973/s), 1.134s (0.0018ms/call) $ perl -MBench -e'$s = "a b"; /(?<a>\w+) (?<a>\w+)/; %h=(a=>$+{a}, b=> +$+{b}); bench sub {$a=$h{a}; $b=$h{b}}, -1' 3333331 calls (3102372/s), 1.074s (0.0003ms/call)

Accessing %+ elements is slower due to some tie magic. In general, yeah, you don't need to worry about it. But I managed to make Org::Parser and Text::sprintfn around twice as fast by avoiding named capture or copying %+ first to a temporary hash instead of accessing invididual %+ elements repeatedly.


In reply to Re^3: No questions. Just a "thank you for named captures" !! by sedusedan
in thread No questions. Just a "thank you for named captures" !! by perl514

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.