Kazuho Oku > Sub-Timekeeper-0.01 > Sub::Timekeeper

Download:
Sub-Timekeeper-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Sub::Timekeeper - calls a function with a stopwatch

SYNOPSIS ^

    use Sub::Timekeeper qw(timekeeper);

    my $val = timekeeper(my $elapsed, sub {
        ...
        return $retval;
    });

    my @arr = timekeeper(my $elapsed, sub {
        ...
        return @retarr;
    });

DESCRIPTION ^

The module exports the timekeeper function, that can be used to measure the time spent to execute a function. The duration is set to the first argument in seconds (as a floating point value).

The duration is set regardless of whether the called function returned normally or by an exception. In other words the following snippet will report the correct duration.

    my $elapsed;
    eval {
        timekeeper($elapsed, sub {
            ...
        }
    };
    if ($@) {
        warn "got error $@ after $elapsed seconds";
    }

AUTHOR ^

Kazuho Oku

LICENSE ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/perl/misc/Artistic.html>

syntax highlighting: