blib/lib/Benchmark/Perl/Formance/Plugin/Prime.pm

filter: Statementstmt 58.5% 24 / 41 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 52.3% 33 / 63 CC 6 SCAR 14.7
CC
6
Cov
53%
crypt_primes
12.0
math_primality
4.3
main
2.0
CRAP 4.4
« 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
BranchTrueFalseTotal
if ($@) 1 0 1
28 1 ▶ print STDERR "# ".$@ if $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} > 2 0 1 1
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
BranchTrueFalseTotal
if ($@) 0 0 0
50 0 ▶ print STDERR "# ".$@ if $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} > 2 0 0 0
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
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
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__
« blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsHash.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/fasta.pm »