Hello,

I recently ran Benchmark on some of my code and am curious as to how best to look at the results.

In the follwing code $link is an object which can be loaded from the database or the cache using the two private functions benchmarked and $criteria is a hashhref.

use Benchmark qw(cmpthese);

cmpthese( 10_000,
    {
      'From Cache' => sub{ $link->_load_from_database( $criteria ); },
      ' From DBI' => sub{ $link->_load_from_cache ( $criteria ); }
    }
  );

Update:

use Benchmark qw(cmpthese); cmpthese( 10_000, { 'From Cache' => sub{ $link->_load_from_cache ( $criteria ); } +, ' From DBI' => sub{ $link->_load_from_database( $criteria ); } } );
The results of the benchmarking are:
Benchmark: timing 10000 iterations of From DBI, From Cache... From DBI: 16 wallclock secs (13.66 usr + 1.50 sys = 15.16 CPU) @ 65 +9.63/s (n=10000) From Cache: 16 wallclock secs ( 6.86 usr + 0.75 sys = 7.61 CPU) @ 13 +14.06/s (n=10000) Rate From DBI From Cache From DBI 660/s -- -50% From Cache 1314/s 99% --
As you can see the Cache code is much faster at 1314/sec (DBI is 660/sec). However the wall clock times for both are the same, and as 10_000 iterations were timed this would imply that in user time there is not much to choose between them.

My question is "how should I look at these results?". What generally accounts for time that Benchmark does not see, and which time result should I use in making performance questions. I hope that this is enough detail for a general discussion as opposed to specifically looking at the code I posted.

-- tidiness is the memory loss of environmental mnemonics

Update per author - dvergin 2003-02-12


In reply to Interpreting Benchmark results. by EvdB

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.