SYNOPSIS

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'.

ATTRIBUTES

name

REQUIRED.

Stores a string name for this item.

code

REQUIRED.

A CodeRef that is to be run.

pre_run

An untimed CodeRef that is executed only once before the run is 'executed'.

buildup

An untimed CodeRef that is executed everytime before 'run' is called.

teardown

An untimed CodeRef that is executed everytime after 'run' is called.

post_run

An untimed CodeRef that is executed only once after the run is 'executed'.

note

An optional string to better explain the item.

results

An ArrayRef that contains all the results.

times

An ArrayRef that contains all the times that a specific run took.

errors

An ArrayRef that contains all any errors that were captured.

METHODS

run

$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.

total_time

The total time that all runs took to execute.

min_time

The fastest execute time.

max_time

The slowest execute time.

avg_time

The averge execute time, total_time / total_runs.

= head2 total_runs

The number of runs that we've captured thus far.