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

filter: Statementstmt 68.0% 32 / 47 Branchbran 20.0% 4 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 3 totaltotal 53.5% 45 / 84 CC 12 SCAR 22.4
CC
12
Cov
53%
run
22.4
print_reverse
6.1
main
5.9
CRAP 9.4
« blib/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/RxCmp.pm »
1 package Benchmark::Perl::Formance::Plugin::Shootout::revcomp;
2 2 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark - Read DNA sequences - write their reverse-complement
4  
5 # COMMAND LINE:
6 # /usr/bin/perl revcomp.perl-4.perl 0 < revcomp-input25000000.txt
7  
8 # The Computer Language Benchmarks Game
9 # http://shootout.alioth.debian.org/
10 #
11 # Contributed by Andrew Rodland
12 # Benchmark::Perl::Formance plugin by Steffen Schwigon
13  
14 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = "0.002";
17  
18 #############################################################
19 # #
20 # Benchmark Code ahead - Don't touch without strong reason! #
21 # #
22 #############################################################
23  
24 2 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Scalar::Util "reftype";
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 our $PRINT = 0;
29  
30 0 ▶sub print_reverse {
Subroutine print_reverse: not called CC=3 SCAR=18.1
Pod undocumented
31 2 ▶ no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
32 0 ▶ while (my $chunk = substr $_[0], -60, 60, '') {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chunk = substr($_[0], -60, 60, "")) 0 0 0
33 0 my $dummy = scalar reverse($chunk);
34 0 ▶ print $dummy, "\n" if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::revcomp::PRINT 0 0 0
35 }
36 }
37  
38 sub run
39 1 ▶{
Subroutine run: called CC=6 SCAR=31.1
Pod undocumented
40 1 my ($infile) = @_;
41  
42 1 my $data;
43  
44 1 my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout" };
45 1 ▶ return { failed => "no Benchmark-Perl-Formance-Cargo" } if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 0 1
46  
47 0 my $srcfile = "$srcdir/$infile";
48 0 ▶ open my $INFILE, "<", $srcfile or die "Cannot read $srcfile";
Branch: 1 branch
BranchTrueFalseTotal
open my $INFILE, "<", $srcfile or die "Cannot read $srcfile" 0 0 0
49  
50 0 ▶ while (<$INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $INFILE)) 0 0 0
51 0 ▶ if (/^>/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^>/) { } 0 0 0
52 0 print_reverse $data;
53 0 ▶ print if $PRINT;
Branch: 1 branch
BranchTrueFalseTotal
if $Benchmark::Perl::Formance::Plugin::Shootout::revcomp::PRINT 0 0 0
54 } else {
55 0 chomp;
56 0 tr{wsatugcyrkmbdhvnATUGCYRKMBDHVN}
57 {WSTAACGRYMKVHDBNTAACGRYMKVHDBN};
58 0 $data .= $_;
59 }
60 }
61 0 close $INFILE;
62 0 print_reverse $data;
63 }
64  
65 sub main
66 1 ▶{
Subroutine main: called CC=5 SCAR=17.8
Pod undocumented
67 1 my ($options) = @_;
68  
69 1 $PRINT = $options->{D}{Shootout_revcomp_print};
70 1 ▶ my $goal = $options->{fastmode} ? "fasta-1000000.txt" : "fasta-1000000.txt";
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
71 1 ▶ my $count = $options->{fastmode} ? 1 : 5;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
72  
73 1 my $result;
74 1 ▶ my $t = timeit $count, sub { $result = run($goal) };
Subroutine __ANON__: called CC=1 SCAR=0.0
75 1 ▶ return $result if reftype($result) eq "HASH" and $result->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result) eq "HASH" and $result->{"failed"} 1 0 1
Condition33%1/3
builtin::reftype($result) eq "HASH" and $result->{"failed"}
!ll&&!rl&&r
001
MC/DC0%0/2
builtin::reftype($result) eq "HASH" and $result->{"failed"}
builtin::reftype($result) eq "HASH" $result->{"failed"}
Truth table33%1/3
A and B
A= builtin::reftype($result) eq "HASH"B= $result->{"failed"}
ABresult
0X0
100
111
76  
77 return {
78 0 Benchmark => $t,
79 goal => $goal,
80 count => $count,
81 result => $result,
82 };
83 }
84  
85 2 1;
86  
87 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/RxCmp.pm »