Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
You slow your program down by using $`. Why do this, when you can simply say (and these tests ALL ASSUME that you are given a FULLY QUALIFIED name, meaning there is at least one :: in it):
($package,$symbol) = $qualified_name =~ /(.*)::(.*)/;
I came up with another method, too, using rindex() and unpack(). I benchmarked yours and mine in separate processes so mine wouldn't be jinxed by yours using $`.
RESULTS: $qualified_name = 'My::Class::Path::func' Benchmark: timing 100000 iterations of Lunatic... Lunatic: 15 wallclock secs (13.99 usr + 0.00 sys = 13.99 CPU) $qualified_name = 'My::Class::Path::myfunc' Benchmark: timing 100000 iterations of Jeff1, Jeff2... Jeff1: 8 wallclock secs ( 8.95 usr + 0.00 sys = 8.95 CPU) Jeff2: 9 wallclock secs ( 8.82 usr + 0.00 sys = 8.82 CPU)
I'll include my code below in a moment. I also tried these on longer qualfied names, SPECIFICALLY one with a longer symbol name. Note: disregard the "wallclock secs" times; they're obviously munged up.
$qualified_name = 'My::Class::Path::myfuncdamnthisisareallylongstring' Benchmark: timing 100000 iterations of Jeff1, Jeff2... Jeff1: 12 wallclock secs (12.54 usr + 0.00 sys = 12.54 CPU) Jeff2: 10 wallclock secs ( 9.55 usr + 0.00 sys = 9.55 CPU) $qualified_name = 'My::REALLYLONGClass::PathPathPath::myfuncdamnthisis +areallylongstring' Benchmark: timing 100000 iterations of Jeff1, Jeff2... Jeff1: 12 wallclock secs (12.73 usr + 0.00 sys = 12.73 CPU) Jeff2: 8 wallclock secs ( 9.14 usr + 0.00 sys = 9.14 CPU) $qualified_name = 'My::REALLYLONGClass::PathPathPath::myfunc' Benchmark: timing 100000 iterations of Jeff1, Jeff2... Jeff1: 11 wallclock secs ( 9.12 usr + 0.00 sys = 9.12 CPU) Jeff2: 8 wallclock secs ( 8.78 usr + 0.00 sys = 8.78 CPU)
And there you have it. It seems my rindex() and unpack() method outruns the regex approach every time. Here it is, for your amusement and edification:
my ($pkg,$sym) = unpack "A" . rindex($qualified_name, "::") . " x2 A*", $qualified_name;

In reply to RE: Parsing Class Paths by japhy
in thread Parsing Class Paths by LunaticLeo

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, 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
  • 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2019-12-10 02:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?