Time::TimeTick - Keep a tally of times at different places in your program
use Time::TimeTick; # Your code... timetick("Starting phase three"); # More of your code...
Time::TimeTick provides a quick and convenient way of instrumenting a program to find out how long it took to reach various points. Just use the module and call the timetick() function whenever you want to mark the time at a point in your program. When the program ends, a report will be output giving the times at which each point was reached.
Time::TimeTick
timetick()
The times will be recorded using Time::HiRes::time() if Time::HiRes is available, otherwise time() will be used. (Since time() has one-second granularity this is unlikely to be useful.)
Time::HiRes::time()
Time::HiRes
time()
To disable the effect of timing with minimal modification to your program, just change ``use Time::TimeTick ...'' to ``no Time::TimeTick...''. The timetick() function will contain no instructions in order to maximize execution speed, and no report will be triggered.
You can customize the action of Time::TimeTick via options passed as key-value pairs in the use statement. Recognized keys are:
use
If true, do not put an initial entry in the report when the module is loaded.
If true, do not put a final entry in the report when the program terminates.
If set, replaces the default entry of ``Timeticker for <program> starting'' output initially (only if suppress_initial is not set.)
suppress_initial
If set, replaces the default entry of ``Timeticker for <program> finishing'' output initially (only if suppress_final is not set.)
suppress_final
If true, report all times relative to the time that Time::TimeTick was loaded rather than the actual start of the program.
If set, should be a reference to a subroutine that will take as input a tag as passed to timetick() and return the actual tag to be used. Can be helpful for applying a lengthy transformation to every tag while keeping the calling code short.
If set, should be a reference to a subroutine that will take as input a list of time ticks for reporting. Each list element will be a reference to an array containing the time and the tag respectively. The default format_report callback is:
format_report
sub { printf("%7.4f %s\n", @$_) for @_ }
If true, do not output a report when report() is called; just reset the time tick list instead.
report()
Record the time at this point of the program and label it with the string $tag.
$tag
Output a report (unless suppress_report is set) and reset the time tick list.
suppress_report
Add a final time tick (unless suppress_final is set), and output a report. Called by default when the program finishes.
Time::TimeTick::timetick is exported to the caller. Note that Time::TimeTick::report is not exported; if you want to call it explicitly you will have to qualify the function name with the package name.
Time::TimeTick::timetick
Time::TimeTick::report
use Time::TimeTick suppress_initial => 1; # ... picture intervening lines of code timetick("Phase 2"); # ... picture more code timetick("Phase 3"); # ... and yet more timetick("Phase 4"); # Some time later, the program ends
Output from Time::TimeTick:
0.7524 Phase 2 0.7945 Phase 3 0.8213 Phase 4 0.8328 Timeticker for testprog finishing
Peter Scott, <Peter@PSDT.com>
Benchmark::Timer, Time::HiRes.
This module was originally written in a modified form and published in the book "Perl Medic" (Addison-Wesley, 2004): http://www.perlmedic.com/. Readers of that book should note that the user interface is different from what appeared there.
http://www.perlmedic.com/
Copyright(c) 2004 Peter Scott.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Time::TimeTick, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::TimeTick
CPAN shell
perl -MCPAN -e shell install Time::TimeTick
For more information on module installation, please visit the detailed CPAN module installation guide.