Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Benchmarking is always tricky: providing subrefs to benchmark makes it easier to get the code right, but if the target code is very fast the sub call overhead can swamp the results. Providing strings instead gets rid of that overhead, but is far harder to get right because the code will be evalled in a different context.

Using a string version of the benchmark, I confirm your results on my system perl (5.28) but the difference almost entirely disappears with 5.34 (which is also quite a bit faster overall):

% perl benchmark Rate methodic blessy direct methodic 16017006/s -- -31% -40% blessy 23189661/s 45% -- -13% direct 26673243/s 67% 15% -- % /opt/v5.34.0/bin/perl benchmark Rate methodic blessy direct methodic 21275455/s -- -39% -39% blessy 34927866/s 64% -- -0% direct 35023414/s 65% 0% -- % cat benchmark use strict; use warnings; use Benchmark; our($mcount, $bcount, $dcount) = (0) x 3; package Methodic { sub new { return bless {} } sub method { ++$::mcount } }; package Blessy { sub new { return bless sub { ++$::bcount } } }; sub direct { ++$::dcount } our $methodic = Methodic->new; our $blessy = Blessy->new; our $direct = \&direct; Benchmark::cmpthese(-1, { methodic => q{$::methodic->method()}, blessy => q{$::blessy->()}, direct => q{$::direct->()}, }); %

Note also that if you look at the counts after the benchmark has run, you'll see larger number than those that were reported. IIRC this is because Benchmark tries to calculate the overhead of calling and adjust results for it, and should not be taken as a sign that it can't count. :)


In reply to Re^7: How to identify the package of a subroutine given only a reference to it by hv
in thread How to identify the package of a subroutine given only a reference to it by drclaw

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



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

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-19 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found