blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/fasta.pm

filter: Statementstmt 100% 77 / 77 Branchbran 59.0% 13 / 22 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 7 totaltotal 79.5% 109 / 137 CC 21 SCAR 14.4
CC
21
Cov
86%
makeRepeatFasta
6.3
makeRandomFasta
6.2
main
5.9
CRAP 4.2
« blib/lib/Benchmark/Perl/Formance/Plugin/Prime.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsClassXSAccessor.pm »
1 package Benchmark::Perl::Formance::Plugin::Shootout::fasta;
2 2 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark - Generate and write random DNA sequences
4  
5 # COMMAND LINE:
6 # /usr/bin/perl fasta.perl-4.perl 25000000
7  
8 # The Computer Language Benchmarks game
9 # http://shootout.alioth.debian.org/
10 #
11 # contributed by David Pyke
12 # tweaked by Danny Sauer
13 # optimized by Steffen Mueller
14 # tweaked by Kuang-che Wu
15 # Benchmark::Perl::Formance plugin by Steffen Schwigon
16  
17 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our $VERSION = "0.002";
21  
22 #############################################################
23 # #
24 # Benchmark Code ahead - Don't touch without strong reason! #
25 # #
26 #############################################################
27  
28 2 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 2 our $PRINT = 0;
31  
32 2 ▶use constant IM => 139968;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use constant IA => 3877;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use constant IC => 29573;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 ▶use constant LINELENGTH => 60;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 2 my $LAST = 42;
39 2667 ▶sub gen_random {
Subroutine gen_random: called CC=2 SCAR=7.2
Pod undocumented
40 2667 ▶ return map {( ($_[0] * ($LAST = ($LAST * IA + IC) % IM)) / IM )} 1..($_[1]||1);
Condition50%1/2
$_[1] || 1
l!l
26670
MC/DC0%0/1
$_[1] || 1
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
41 }
42  
43 2 ▶sub makeCumulative {
Subroutine makeCumulative: called CC=2 SCAR=6.9
Pod undocumented
44 2 my $genelist = shift;
45 2 my $cp = 0.0;
46  
47 2 $_->[1] = $cp += $_->[1] foreach @$genelist;
48 }
49  
50 2667 ▶sub selectRandom {
Subroutine selectRandom: called CC=5 SCAR=16.1
Pod undocumented
51 2667 my $genelist = shift;
52 2667 ▶ my $number = shift || 1;
Condition50%1/2
shift() || 1
l!l
26670
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
53 2667 my @r = gen_random(1, $number);
54  
55 2667 my $s;
56 2667 foreach my $r (@r) {
57 160000 foreach (@$genelist){
58 498736 ▶ if ($r < $_->[1]) { $s .= $_->[0]; last; }
Branch: 1 branch
BranchTrueFalseTotal
if ($r < $_->[1]) 160000 338736 498736
59 }
60 }
61  
62 2667 return $s;
63 }
64  
65  
66 2 ▶sub makeRandomFasta {
Subroutine makeRandomFasta: called CC=6 SCAR=18.3
Pod undocumented
67 2 my ($id, $desc, $n, $genelist) = @_;
68  
69 2 ▶ print ">", $id, " ", $desc, "\n" if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 2 2
70  
71 # print whole lines
72 2 foreach (1 .. int($n / LINELENGTH) ){
73 2666 my $dummy = selectRandom($genelist, LINELENGTH)."\n";
74 2666 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 2666 2666
75 }
76 # print remaining line (if required)
77 2 ▶ if ($n % LINELENGTH){
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 60) 1 1 2
78 1 my $dummy = selectRandom($genelist, $n % LINELENGTH)."\n";
79 1 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 1 1
80 }
81 }
82  
83 1 ▶sub makeRepeatFasta {
Subroutine makeRepeatFasta: called CC=6 SCAR=18.5
Pod undocumented
84 1 my ($id, $desc, $s, $n) = @_;
85  
86 1 ▶ print ">", $id, " ", $desc, "\n" if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 1 1
87  
88 1 my $r = length $s;
89 1 my $ss = $s . $s . substr($s, 0, $n % $r);
90 1 for my $j(0..int($n / LINELENGTH)-1) {
91 666 my $i = $j*LINELENGTH % $r;
92 666 my $dummy = substr($ss, $i, LINELENGTH)."\n";
93 666 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 666 666
94 }
95 1 ▶ if ($n % LINELENGTH) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n % 60) 1 0 1
96 1 my $dummy = substr($ss, -($n % LINELENGTH)). "\n";
97 1 ▶ print $dummy if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::fasta::PRINT 0 1 1
98 }
99 }
100  
101  
102 2 my $iub = [
103 [ 'a', 0.27 ],
104 [ 'c', 0.12 ],
105 [ 'g', 0.12 ],
106 [ 't', 0.27 ],
107 [ 'B', 0.02 ],
108 [ 'D', 0.02 ],
109 [ 'H', 0.02 ],
110 [ 'K', 0.02 ],
111 [ 'M', 0.02 ],
112 [ 'N', 0.02 ],
113 [ 'R', 0.02 ],
114 [ 'S', 0.02 ],
115 [ 'V', 0.02 ],
116 [ 'W', 0.02 ],
117 [ 'Y', 0.02 ]
118 ];
119  
120 2 my $homosapiens = [
121 [ 'a', 0.3029549426680 ],
122 [ 'c', 0.1979883004921 ],
123 [ 'g', 0.1975473066391 ],
124 [ 't', 0.3015094502008 ]
125 ];
126  
127 2 my $alu =
128 'GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG' .
129 'GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA' .
130 'CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT' .
131 'ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA' .
132 'GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG' .
133 'AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC' .
134 'AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA';
135  
136 ######################################################################
137 #main
138  
139 sub run
140 1 ▶{
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
141 1 my ($n) = @_;
142  
143 1 makeCumulative($iub);
144 1 makeCumulative($homosapiens);
145  
146 1 makeRepeatFasta ('ONE', 'Homo sapiens alu', $alu, $n*2);
147 1 makeRandomFasta ('TWO', 'IUB ambiguity codes', $n*3, $iub);
148 1 makeRandomFasta ('THREE', 'Homo sapiens frequency', $n*5, $homosapiens);
149 }
150  
151 sub main
152 1 ▶{
Subroutine main: called CC=5 SCAR=17.8
Pod undocumented
153 1 my ($options) = @_;
154  
155 1 $PRINT = $options->{D}{Shootout_fasta_print};
156 1 ▶ my $goal = $options->{D}{Shootout_fasta_n} || ($options->{fastmode} ? 20_000 : 5_000_000);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
Condition33%1/3
$options->{'D'}{'Shootout_fasta_n'} || ($options->{'fastmode'} ? 20000 : 5000000)
l!l&&r!l&&!r
010
MC/DC0%0/2
$options->{'D'}{'Shootout_fasta_n'} || ($options->{'fastmode'} ? 20000 : 5000000)
$options->{'D'}{'Shootout_fasta_n'} ($options->{'fastmode'} ? 20000 : 5000000)
Truth table33%1/3
A || B
A= $options->{'D'}{'Shootout_fasta_n'}B= ($options->{'fastmode'} ? 20000 : 5000000)
ABresult
1X1
011
000
157 1 ▶ my $count = $options->{D}{Shootout_fasta_count} || ($options->{fastmode} ? 1 : 5);
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
Condition33%1/3
$options->{'D'}{'Shootout_fasta_count'} || ($options->{'fastmode'} ? 1 : 5)
l!l&&r!l&&!r
010
MC/DC0%0/2
$options->{'D'}{'Shootout_fasta_count'} || ($options->{'fastmode'} ? 1 : 5)
$options->{'D'}{'Shootout_fasta_count'} ($options->{'fastmode'} ? 1 : 5)
Truth table33%1/3
A || B
A= $options->{'D'}{'Shootout_fasta_count'}B= ($options->{'fastmode'} ? 1 : 5)
ABresult
1X1
011
000
158  
159 1 my $result;
160 1 ▶ my $t = timeit $count, sub { $result = run($goal) };
Subroutine __ANON__: called CC=1 SCAR=0.0
161 return {
162 1 Benchmark => $t,
163 goal => $goal,
164 count => $count,
165 result => $result,
166 };
167 }
168  
169 2 1;
170  
171 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/Prime.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/AccessorsClassXSAccessor.pm »