Benchmark-Stopwatch
view release on metacpan or search on metacpan
lib/Benchmark/Stopwatch.pm view on Meta::CPAN
The other benchmark modules provide excellent timing for specific parts of
your code. This module aims to allow you to easily time the progression of
your code.
The stopwatch analogy is that at some point you get a C<new> stopwatch and
C<start> timing. Then you note certain events using C<lap>. Finally you
C<stop> the watch and then print out a C<summary>.
The summary shows all the events in order, what time they occured at, how long
since the last lap and the percentage of the total time. Hopefully this will
give you a good idea of where your code is spending most of its time.
The times are all wallclock times in fractional seconds.
That's it.
=head1 METHODS
=head2 new
lib/Benchmark/Stopwatch.pm view on Meta::CPAN
my $prev_time = $self->{start};
push @{ $self->{events} }, { name => '_stop_', time => $self->{stop} };
$out .= sprintf $header_format, qw( NAME TIME CUMULATIVE PERCENTAGE);
foreach my $event ( @{ $self->{events} } ) {
my $duration = $event->{time} - $prev_time;
my $cumulative = $event->{time} - $self->{start};
my $percentage = ( $duration / $self->total_time ) * 100;
$out .= sprintf $result_format, #
$event->{name}, #
$duration, #
$cumulative, #
$percentage;
$prev_time = $event->{time};
}
pop @{ $self->{events} };
return $out;
}
=head2 as_data
( run in 0.480 second using v1.01-cache-2.11-cpan-709fd43a63f )