PerlStone2015/regexdna.pm

filter: Statementstmt 30.5% 18 / 59 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 2 totaltotal 25.5% 23 / 90 CC 12 SCAR 36.5
CC
12
Cov
23%
run
72.0
main
30.0
__ANON__
2.0
CRAP 38.6
« PerlStone2015/dpath.pm ↑ Summary PerlStone2015/fasta.pm »
1 package Benchmark::Perl::Formance::Plugin::PerlStone2015::regexdna;
2 1 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark - Match DNA 8-mers and substitute nucleotides for IUB codes
4 1 $Benchmark::Perl::Formance::Plugin::PerlStone2015::regexdna::VERSION = '0.002';
5 # COMMAND LINE:
6 # /usr/bin/perl regexdna.perl-2.perl 0 < regexdna-input5000000.txt
7  
8 # The Computer Language Benchmarks Game
9 # http://shootout.alioth.debian.org/
10 # contributed by Danny Sauer
11 # completely rewritten and
12 # cleaned up for speed and fun by Mirco Wahab
13 # improved STDIN read, regex clean up by Jake Berner
14 # More speed and multithreading by Andrew Rodland
15 # Benchmark::Perl::Formance plugin by Steffen Schwigon
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #############################################################
21 # #
22 # Benchmark Code ahead - Don't touch without strong reason! #
23 # #
24 #############################################################
25  
26 1 ▶use File::ShareDir qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Scalar::Util "reftype";
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub run
31 0 ▶{
Subroutine run: not called CC=8 SCAR=42.8
Pod undocumented
32 0 my ($infile) = @_;
33  
34 0 my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout" };
35 0 ▶ return { failed => "no Benchmark-Perl-Formance-Cargo" } if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
36  
37 0 my $srcfile = "$srcdir/$infile";
38 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
39  
40 0 my $l_file = -s $INFILE;
41 0 my $content; read $INFILE, $content, $l_file;
42 # this is significantly faster than using <> in this case
43 0 close $INFILE;
44  
45 0 $content =~ s/^>.*//mg;
46 0 $content =~ tr/\n//d;
47 0 my $l_code = length $content;
48  
49 0 my @seq = ( 'agggtaaa|tttaccct',
50 '[cgt]gggtaaa|tttaccc[acg]',
51 'a[act]ggtaaa|tttacc[agt]t',
52 'ag[act]gtaaa|tttac[agt]ct',
53 'agg[act]taaa|ttta[agt]cct',
54 'aggg[acg]aaa|ttt[cgt]ccct',
55 'agggt[cgt]aa|tt[acg]accct',
56 'agggta[cgt]a|t[acg]taccct',
57 'agggtaa[cgt]|[acg]ttaccct' );
58  
59 0 my @procs;
60 0 for my $s (@seq) {
61 0 my $pat = qr/$s/;
62 0 my $pid = open my $fh, '-|';
63 0 ▶ defined $pid or die "Error creating process";
Branch: 1 branch
BranchTrueFalseTotal
defined $pid or die "Error creating process" 0 0 0
64 0 ▶ unless ($pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 0 0
65 0 my $cnt = 0;
66 0 ▶ ++$cnt while $content =~ /$pat/gi;
Branch: 1 branch
BranchTrueFalseTotal
$content =~ /$pat/gi and do { ++$cnt } 0 0 0
67 0 print "$s $cnt\n";
68 0 exit 0;
69 }
70 0 push @procs, $fh;
71 }
72  
73 0 for my $proc (@procs) {
74 #print
75 0 <$proc>;
76 0 close $proc;
77 }
78  
79 0 my %iub = ( B => '(c|g|t)', D => '(a|g|t)',
80 H => '(a|c|t)', K => '(g|t)', M => '(a|c)',
81 N => '(a|c|g|t)', R => '(a|g)', S => '(c|g)',
82 V => '(a|c|g)', W => '(a|t)', Y => '(c|t)' );
83  
84 # We could cheat here by using $& in the subst and doing it inside a string
85 # eval to "hide" the fact that we're using $& from the rest of the code... but
86 # it's only worth 0.4 seconds on my machine.
87 0 my $findiub = '(['.(join '', keys %iub).'])';
88  
89 0 $content =~ s/$findiub/$iub{$1}/g;
90  
91 return {
92 0 length_file => $l_file,
93 length_code => $l_code,
94 length_content => length $content,
95 };
96 }
97  
98 sub main
99 0 ▶{
Subroutine main: not called CC=5 SCAR=34.0
Pod undocumented
100 0 my ($options) = @_;
101  
102 0 ▶ my $goal = $options->{fastmode} ? "fasta-100000.txt" : "fasta-1000000.txt";
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
103 0 ▶ my $count = $options->{fastmode} ? 5 : 10;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
104  
105 0 my $result;
106 0 ▶ my $t = timeit $count, sub { $result = run($goal) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 0 ▶ return $result if reftype($result) eq "HASH" and $result->{failed};
Branch: 1 branch
BranchTrueFalseTotal
if builtin::reftype($result) eq "HASH" and $result->{"failed"} 0 0 0
Condition0%0/3
builtin::reftype($result) eq "HASH" and $result->{"failed"}
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($result) eq "HASH" and $result->{"failed"}
builtin::reftype($result) eq "HASH" $result->{"failed"}
Truth table0%0/3
A and B
A= builtin::reftype($result) eq "HASH"B= $result->{"failed"}
ABresult
0X0
100
111
108  
109 return {
110 0 Benchmark => $t,
111 goal => $goal,
112 count => $count,
113 result => $result,
114 };
115 }
116  
117 1 1;
118  
119 __END__
« PerlStone2015/dpath.pm ↑ Summary PerlStone2015/fasta.pm »