NAME

LinkedList::Single::Example::Bench - shared timing, memory, and complexity helpers

SYNOPSIS

use FindBin::libs;
use LinkedList::Single::Example::Bench qw( best_of complexity report );

my $secs    = best_of 3 => sub { ... };
my $cx      = complexity \&Some::Package::method;

DESCRIPTION

Every example in LinkedList::Single::Examples compares a LinkedList::Single solution with the plain-array solution to the same problem. These helpers keep the comparisons the same from one example to the next.

best_of( $reps, $code )

Fastest of $reps runs of $code, in seconds.

complexity( $code )

Deparses $code and returns a hashref counting statements, branches, and index_ops (element access, $#, and splice). The last is the position arithmetic that a cursor makes unnecessary.

array_bytes( $aref ), list_bytes( $list )

Container overhead in bytes: the array's allocated capacity, which stays at its high-water mark after shift, versus the sum of the live nodes of the list.

report( $title, @row )

Prints a table of rows with name, secs, optional bytes, and cx (as returned by complexity).