The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Time::SoFar - Perl module to calculate run time

SYNOPSIS

    use Time::SoFar qw( runtime runinterval figuretimes );

    # [...] denotes optional arguments
    $times = runtime( [$no_optimize] );
    @times = runtime( [$no_optimize] );

    $times = runinterval( [$no_optimize] );
    @times = runinterval( [$no_optimize] );

    $times = figuretimes( $seconds [, $no_optimize] );
    @times = figuretimes( $seconds [, $no_optimize] );

SAMPLES

    my $elapsed = runtime();
    print "Elapsed time $elapsed\n";
    # prints, eg, "Elapsed time 17:34\n"

    my $sincethen = runinterval(1);
    print "Time since then $sincethen\n";
    # prints, eg, "Time since then 0:00:00:51\n"

    ($day, $hour, $min, $sec) = figuretimes(86400 + 2*3600 + 3*60 + 4, 1);
    # $day = 1; $hour = 2; $min = 3; $sec = 4;
    
    @times = figuretimes(2*3600 + 3*60 + 4);
    # @times = (2, 3, 4)
    
    @times = figuretimes(17,1);
    # @times = (0, 0, 0, 17)
    
    $times = figuretimes(2*3600 + 3*60 + 4, 1);
    # $times = '0:02:03:04';

DESCRIPTION

Time::SoFar has two functions for calculating how long a script has been running. runtime() always works from the time the script was started (using $^T). runinterval() works from the last time runtime() or runinterval() was called (or since the start of the script).

Both runtime() and runinterval() use figuretimes() to render a raw number of seconds into component time units. Both take an optional boolean argument that gets passed to figuretimes() to influence its output.

In an array context figuretimes() returns the timecomponents as an array, in a scalar context it returns those components as a : delimited string. The default behaviour is to optimize away 0 output from the longer period end of the output, leaving a minimum of minutes:seconds. This is good for arrays that will be passed to join(), but not so good for a list of variables, so this behaviour can be disabled by using a true value for $no_optimize.

INHERITANCE

Time::SoFar inherits only from Exporter.

CAVEATS

Time::SoFar has a granularity of seconds, and is therefore not so useful for small elapsed times.

PREREQUISITES

Only stock perl modules are used.

OSNAMES

So long as $^T and time() are calculated using the same epoch there should be no operating system dependence.

SEE ALSO

$^T in perlvar.

COPYRIGHT

Copyright 2000 by Eli the Bearded / Benjamin Elijah Griffin. Released under the same license(s) as Perl.

AUTHOR

Eli the Bearded wrote this to do away with all the $^T one liners at the end of his batch processing scripts.