« blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/spectralnorm.pm
↑ Summary
blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/binarytrees.pm »
| 1 | package Benchmark::Perl::Formance::Plugin::FibOOSig; | ||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:SCHWIGON'; | |||||||||
| 3 | # ABSTRACT: benchmark plugin - FibOOSig - Stress recursion and method calls (plain OO with function signatures) | ||||||||||
| 4 | |||||||||||
| 5 | # Fibonacci numbers, using methods with signatures (Perl 5.20+) | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
| |||||||||||
| 8 | 1 | ▶ | if ($] < 5.020) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 9 | 0 | die "Perl 5.020+ required for subs with signatures.\n"; | |||||||||
| 10 | } | ||||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | no warnings 'experimental::signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | our $VERSION = "0.002"; | |||||||||
| 19 | |||||||||||
| 20 | ############################################################# | ||||||||||
| 21 | # # | ||||||||||
| 22 | # Benchmark Code ahead - Don't touch without strong reason! # | ||||||||||
| 23 | # # | ||||||||||
| 24 | ############################################################# | ||||||||||
| 25 | |||||||||||
| 26 | 1 | our $goal; | |||||||||
| 27 | 1 | our $count; | |||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | use Benchmark ':hireswallclock'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 32 | 0 | bless {}, shift; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | sub fib ($self, $n) | ||||||||
|
Subroutine
fib: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 36 | { | ||||||||||
| 37 | 0 | ▶ | $n < 2 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | ? 1 | ||||||||||
| 39 | : $self->fib($n-1) + $self->fib($n-2); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub main | ||||||||||
| 43 | 0 | ▶ | { | ||||||||
|
Subroutine
main: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 44 | 0 | my ($options) = @_; | |||||||||
| 45 | |||||||||||
| 46 | # ensure same values over all Fib* plugins! | ||||||||||
| 47 | 0 | ▶ | $goal = $options->{fastmode} ? 20 : 35; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $count = 5; | |||||||||
| 49 | |||||||||||
| 50 | 0 | my $result; | |||||||||
| 51 | 0 | my $fib = __PACKAGE__->new; | |||||||||
| 52 | 0 | ▶ | my $t = timeit $count, sub { $result = $fib->fib($goal) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | return { | ||||||||||
| 54 | 0 | Benchmark => $t, | |||||||||
| 55 | result => $result, | ||||||||||
| 56 | goal => $goal, | ||||||||||
| 57 | }; | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 1 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||