readme
time-command
This module provides an easy interface to the GNU time command (usually installed as
'/usr/bin/time') to time user commands.
SYNOPSIS
use GNU::Time;
my $cmd = "some-user-prog arg1 arg2";
my $user-time = time-command $cmd;
say $user-time; # output: 42.70 # seconds
Note: This module replaces module `Proc::More` which is deprecated.
Getting the time command
On Debian hosts the time command may not be installed by default, but
it is available in package time. It can also be built from source
available at the Free Software Foundation's git site. Clone the
source repository:
$ git clone https://git.savannah.gnu.org/git/time.git
The build and install instructions are in the repository along with the source code.
Unfortunately, there is no equivalent command available for Windows unless you install Cygwin or an equivalent system.
The GNU time command
The details for running time are described in time's man page which can be viewed by
running man 1 time at the command line.
This module will look for time in the following locations and order:
The location defined by the
GNU_TIMEenvironment variable/usr/local/bin/time/usr/bin/time
If the time command is not found, an exception will be thrown.
Likewise, if the time command returns an exit code other than
zero, an exception will be thrown.
# The Proc::More module
The routines are described in detail in [ALL-SUBS](https://github.com/tbrowder/Proc-More/blob/master/docs/ALL-SUBS.md) which shows a short description of each exported routine along with its complete signature.
## The :$typ and :$fmt named parameters
The two named parameters control the type and format of the output
from the time-command. (Note there is a fourth format which is used
if the :$fmt variable is not used or defined. In that case only
the raw time in seconds is shown without any other formatting.) The
allowed values and a short description are described in the source
code and are repeated here:
my token typ { ^ :i # the desired time(s) to return:
a|all| # show all three times:
# "Real: [time in desired format]; User: [ditto]; Sys: [ditto]"
r|real| # show only the real (wall clock) time
u|user| # show only the user time (default)
s|sys # show only the system time
$ }
my token fmt { ^ :i # the desired format for the returned time(s)
s|seconds| # time in seconds with an appended 's': "30.42s"
h|hms| # time in hms format: "0h00m30.42s"
':'|'h:m:s' # time in h:m:s format: "0:00:30.42"
$ }
Contributing
Interested users are encouraged to contribute improvements and corrections to this module, and pull requests, bug reports, and suggestions are always welcome.
AUTHOR
Tom Browder ([email protected])
COPYRIGHT and LICENSE
Copyright Ā© 2017-2021 Tom rowder
This library is free software; you may redistribute or modify it under the Artistic License 2.0.