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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |