Answer to number 3: run (under windows)
perldoc Benchmark
to read the POD for the module. If you have a somewhat old and/or broken install (like me), you can always fall back to
vi \perl\lib\Benchmark.pm
:)

What you've written is a proper way of using benchmark. Ideally, you would insert several objects into your code to get the times you wanted, but you can do it in a clever and inobtrusive manner:

BEGIN { use Benchmark; my ($oldb, $newb); # inside BEGIN for closure sub mybench { return unless ($opt_b); $newb = new Benchmark; if ($oldb) { # i.e. don't run first time through print timediff($oldb, $newb); } $oldb = $newb; } } Getopt::Std; getopts('b'); mybench(); # some code here mybench(); # some more code here mybench();
and then it would be trivial to remove the benchmarking from your production code, either through a command line switch, as above:
mycode.pl -b
or some line in your makefile like:
perl -lne 'print unless /^\s*mybench();/' myscript.pl > production.pl
ya know.

In reply to Re: Re: Question about benchmarking by Anonymous Monk
in thread Question about benchmarking by jryan

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.