Here's a module I made that gets a lot of use. It times the total runtime of a perl script and prints the runtime and script name at the terminal. The only thing needed to make it time a script is to put "use Timer::Runtime" into the script.
I'd like to request some peer review and ask for any suggestions.
The output if this is used on 'myscript.pl' would look like:
myscript.pl Started: Thu Aug 12 20:34:49 2010
myscript.pl Finished: Thu Aug 12 20:34:49 2010, time = 00:00:00.000114
Here is what the module looks like:
package Timer::Runtime;
use strict;
use Time::Elapse;
Time::Elapse->lapse( my $now);
BEGIN {
print "$0 Started: " . ( scalar localtime ) . "\n";
}
END {
print "$0 Finished: " . ( scalar localtime ) . ", time = $now\n";
}
1;
=head1 NAME
Timer::Runtime
=head1 SYNOPSIS
Wrap a script up with only a use statement to denote its start, stop,
+and duration times to STDOUT.
=head1 DESCRIPTION
=over
use Timer::Runtime;
# output
<script_name> Started: Thu Aug 12 20:34:49 2010
<script_name> Finished: Thu Aug 12 20:34:49 2010, time = 00:00:00.
+000114
=back
=head1 Author
awohld
=cut
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.