Here you are, looking at the object for one specific item. At this level things start to look much more like the unix 'time' command as this is a clock wrapped around a single 'item'.
As a matter of comparison, lets look at a simple example:
time perl -e 'for(1..3){print $_}'
As a Tool::Bench::Item things would look something like:
my $item = Tool::Bench::Item->new( name => 'Example', code => sub{qx{perl -e 'for(1..3){print $_}'}}, # to be fair we call perl again to include compile time ); $item->run; printf qq{%0.3f\n} $item->times->[0];
This is a very simple example, with very simular outcomes. But there's more that an item provides, speciflcy the startup and teardown events. These are untimed CodeRefs that get run before and after the core 'code'.
Here is another set of examples comparing to 'time':
echo 'hello' > /tmp/example && time cat /tmp/example && rm /tmp/example Tool::Bench::Item->new( name => 'Example with startup and teardown', startup => sub{qx{echo 'hello' > /tmp/example}}, code => sub{qx{cat /tmp/example}}, teardown => sub{qx{rm /tmp/example}}, )->run;
In both cases we only timed 'cat' not 'echo' or 'rm'.
REQUIRED.
Stores a string name for this item.
A CodeRef that is to be run.
An untimed CodeRef that is executed only once before the run is 'executed'.
An untimed CodeRef that is executed everytime before 'run' is called.
An untimed CodeRef that is executed everytime after 'run' is called.
An untimed CodeRef that is executed only once after the run is 'executed'.
An optional string to better explain the item.
An ArrayRef that contains all the results.
An ArrayRef that contains all the times that a specific run took.
An ArrayRef that contains all any errors that were captured.
$item->run; # a single run $item->run(3); # run the code 3 times
Execute code and capture results, errors, and the time for each run.
The total time that all runs took to execute.
The fastest execute time.
The slowest execute time.
The averge execute time, total_time / total_runs.
= head2 total_runs
The number of runs that we've captured thus far.
To install Tool::Bench, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tool::Bench
CPAN shell
perl -MCPAN -e shell install Tool::Bench
For more information on module installation, please visit the detailed CPAN module installation guide.