| Devel-PerlySense documentation | Contained in the Devel-PerlySense distribution. |
Devel::TimeThis - Time the duration of a variable until it goes out of scope
Create new TimeThis object.
Invocations with the same $name will be reported together.
Collect the timing data
Print timing data
Johan Lindström, <johanl[ÄT]DarSerMan.com>
Please report any bugs or feature requests to
bug-devel-perlysense@rt.cpan.org, or through the web interface at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.
Copyright 2005 Johan Lindström, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Devel-PerlySense documentation | Contained in the Devel-PerlySense distribution. |
use strict; use warnings; package Devel::TimeThis; our $VERSION = '0.01'; use Carp; use Data::Dumper; use Time::HiRes qw/time/;
my $rhNameInfo = {};
sub new() { my $self = bless {}, shift; my ($name) = @_; $self->{timeStart} = time(); $self->{name} = $name; return($self); }
sub DESTROY { my ($self) = @_; my $timeDuration = time() - $self->{timeStart}; $rhNameInfo->{$self->{name}}->{timeDurationAcc} += $timeDuration; $rhNameInfo->{$self->{name}}->{count}++; $rhNameInfo->{$self->{name}}->{name} = $self->{name}; }
sub END { keys %$rhNameInfo and print qq{ * Timing info * }; for my $rhInfo ( sort { $b->{timeDurationAcc} <=> $a->{timeDurationAcc} } values %$rhNameInfo) { printf("% 40s: % 4d : %3.5f\n", $rhInfo->{name}, $rhInfo->{count}, $rhInfo->{timeDurationAcc}); } } 1; __END__