| 1 | package Test::Evo::Benchmark; | ||||||||||
| 2 | 5 | ▶ | use Evo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use parent 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use Test::More; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | ▶ | use Carp 'croak'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 5 | ▶ | use Benchmark 'timeit'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | our @EXPORT = qw(faster_ok); | |||||||||
| 10 | |||||||||||
| 11 | sub faster_ok { | ||||||||||
| 12 | 0 | ▶ | my %args = @_; | ||||||||
|
Subroutine
faster_ok: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 13 | |||||||||||
| 14 | 0 | ▶ | $args{$_} or croak "define $_ option" for qw(iters fn expect); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 0 | my ($iters, $fn, $expect, $diag) = @args{qw(iters fn expect diag)}; | |||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 0 | my $t = timeit($iters, $fn); | |||||||||
| 19 | 0 | local $Test::Builder::Level = $Test::Builder::Level + 1; | |||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | if ($t->cpu_a) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | my $perf = $iters / $t->cpu_a; | |||||||||
| 23 | 0 | ▶ | do { diag timestr $t; diag $perf } if $diag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | ok $perf > $expect, "$perf > $expect"; | |||||||||
| 25 | } | ||||||||||
| 26 | else { | ||||||||||
| 27 | 0 | fail "too few itreations $iters"; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | $t; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 5 | 1; | |||||||||
| 34 | |||||||||||
| 35 | __END__ | ||||||||||