« 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
| |||||||||||||||||||||||||||||
| 33 | 0 | my $dummy = scalar reverse($chunk); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | print $dummy, "\n" if $PRINT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | my $srcfile = "$srcdir/$infile"; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | open my $INFILE, "<", $srcfile or die "Cannot read $srcfile"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | while (<$INFILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if (/^>/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | print_reverse $data; | |||||||||||||||||||||||||||
| 53 | 0 | ▶ | print if $PRINT; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | my $count = $options->{fastmode} ? 1 : 5; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
builtin::reftype($result) eq "HASH" and $result->{"failed"}
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"}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||