G'day Chris,

Perhaps you're looking for something like this:

#!/usr/bin/env perl -l BEGIN { use Time::HiRes 'time'; $::t0 = time; print "BEGIN: $::t0"; } use strict; use warnings; CHECK { $::t1 = time; print "CHECK: $::t1"; print 'DIFF: ', $::t1 - $::t0; } INIT { $::t2 = time; print "INIT: $::t2"; } END { $::t3 = time; print "END: $::t3"; print 'DIFF: ', $::t3 - $::t2; print 'Total: ', $::t3 - $::t0; }

Obviously, that won't include use Time::HiRes 'time'; in the timings: that might be a good thing. Here's a couple of sample runs:

BEGIN: 1385861138.48632 CHECK: 1385861138.48653 DIFF: 0.000216007232666016 INIT: 1385861138.48655 END: 1385861138.48658 DIFF: 2.40802764892578e-05 Total: 0.000259876251220703
BEGIN: 1385861139.78308 CHECK: 1385861139.78329 DIFF: 0.000212907791137695 INIT: 1385861139.78331 END: 1385861139.78333 DIFF: 2.38418579101562e-05 Total: 0.00025486946105957

BEGIN to CHECK is the compile time; INIT to END is the execution time: see "perlmod: BEGIN, UNITCHECK, CHECK, INIT and END" if you're unfamiliar with these.

Earlier responses have pointed out that "times vary": I'll assume you've understood the issues here. With substantially more compilation/runtime processing (than I've shown here) you may start to see more consistent results.

You haven't indicated what you want to use this for. Averaging results from multiple runs, at different times of the day, or under different loads, would probably be more useful than taking individual snapshots and trying to infer whatever from them.

-- Ken


In reply to Re: How can one best measure compile time of their Perl script? by kcott
in thread How can one best measure compile time of their Perl script? by taint

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.