« blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsHash.pm
↑ Summary
blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/fasta.pm »
| 1 | package Benchmark::Perl::Formance::Plugin::Prime; | ||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:SCHWIGON'; | |||||||||
| 3 | # ABSTRACT: benchmark plugin - Prime - Stress math libs (Math::GMPz) | ||||||||||
| 4 | |||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | our $VERSION = "0.001"; | |||||||||
| 9 | |||||||||||
| 10 | ############################################################# | ||||||||||
| 11 | # # | ||||||||||
| 12 | # Benchmark Code ahead - Don't touch without strong reason! # | ||||||||||
| 13 | # # | ||||||||||
| 14 | ############################################################# | ||||||||||
| 15 | |||||||||||
| 16 | 2 | our $goal; | |||||||||
| 17 | 2 | our $count; | |||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | use Benchmark ':hireswallclock'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | sub math_primality | ||||||||||
| 22 | 1 | ▶ | { | ||||||||
|
Subroutine
math_primality: called CC=3 SCAR=14.7
Pod
undocumented
| |||||||||||
| 23 | 1 | my ($options) = @_; | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | eval "use Math::Primality 'next_prime'"; ## no critic | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 1 | ▶ | print STDERR "# ".$@ if $options->{verbose} > 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 1 | return { failed => "use Math::Primality failed" }; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 0 | my $t; | |||||||||
| 33 | my $result; | ||||||||||
| 34 | 0 | my $numgoal = 10 ** $goal; | |||||||||
| 35 | 0 | ▶ | $t = timeit $count, sub { $result = next_prime($numgoal) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | return { | ||||||||||
| 37 | 0 | Benchmark => $t, | |||||||||
| 38 | result => "$result", # stringify from blessed | ||||||||||
| 39 | goal => $goal, | ||||||||||
| 40 | numgoal => $numgoal, | ||||||||||
| 41 | }; | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub crypt_primes | ||||||||||
| 45 | 0 | ▶ | { | ||||||||
|
Subroutine
crypt_primes: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 46 | 0 | my ($options) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 0 | eval "use Crypt::Primes 'maurer'"; ## no critic | |||||||||
| 49 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | ▶ | print STDERR "# ".$@ if $options->{verbose} > 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | return { failed => "use Crypt::Primes failed" }; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | my $t; | |||||||||
| 55 | my $result; | ||||||||||
| 56 | 0 | my $bitgoal = int($goal * 3.36); # bitness in about same size order as int length in math_primality | |||||||||
| 57 | 0 | ▶ | $t = timeit $count, sub { $result = maurer(Size => $bitgoal) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 58 | return { | ||||||||||
| 59 | 0 | Benchmark => $t, | |||||||||
| 60 | result => "$result", # stringify from blessed | ||||||||||
| 61 | goal => $goal, | ||||||||||
| 62 | bitgoal => $bitgoal, | ||||||||||
| 63 | }; | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | ▶ | sub main { | ||||||||
|
Subroutine
main: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 67 | 1 | my ($options) = @_; | |||||||||
| 68 | |||||||||||
| 69 | 1 | ▶ | $goal = $options->{fastmode} ? 15 : 22; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | $count = 5; | |||||||||
| 71 | |||||||||||
| 72 | return { | ||||||||||
| 73 | 1 | math_primality => math_primality($options), | |||||||||
| 74 | #crypt_primes => crypt_primes($options), # disabled - does not run in constant time by nature | ||||||||||
| 75 | }; | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 2 | 1; | |||||||||
| 79 | |||||||||||
| 80 | __END__ | ||||||||||