| 1 | package Benchmark::DKbench; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Digest; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Digest::MD5 qw(md5_hex); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Spec::Functions; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use List::Util qw(min max sum); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Time::HiRes; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Astro::Coord::Constellations 'constellation_for_eq'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Astro::Coord::Precession 'precess'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Crypt::JWT qw(encode_jwt decode_jwt); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use CSS::Inliner; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use File::ShareDir 'dist_dir'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use HTML::FormatText; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use HTML::TreeBuilder; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Imager; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Imager::Filter::Mandelbrot; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Image::PHash; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use Math::DCT ':all'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Math::MatrixReal; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use MCE::Loop; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use Sys::Info; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use Sys::Info::Constants qw( :device_cpu ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 3 | our @EXPORT = qw(system_identity suite_run calc_scalability); | |||||||||||||||||||||||||||||||||||||
| 34 | 3 | our $datadir = dist_dir("Benchmark-DKbench"); | |||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | 3 | our $VERSION = '2.0'; | |||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | Benchmark::DKbench - Perl Benchmark | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | # Run the suite single-threaded and then multi-threaded on multi-core systems | ||||||||||||||||||||||||||||||||||||||
| 45 | # Will print scores for the two runs and multi/single thread scalability | ||||||||||||||||||||||||||||||||||||||
| 46 | dkbench | ||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||
| 48 | # A dual-thread run with times instead of scores | ||||||||||||||||||||||||||||||||||||||
| 49 | dkbench -j 2 -t | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | # If BioPerl is installed, enable the BioPerl benchmarks by downloading Genbank data | ||||||||||||||||||||||||||||||||||||||
| 52 | dkbench --setup | ||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | # Force install the reference versions of all CPAN modules | ||||||||||||||||||||||||||||||||||||||
| 55 | setup_dkbench --force | ||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | A Perl benchmark suite for general compute, created to evaluate the comparative | ||||||||||||||||||||||||||||||||||||||
| 60 | performance of systems when running computationally intensive Perl (both pure Perl | ||||||||||||||||||||||||||||||||||||||
| 61 | and XS) workloads. Runs single and multi-threaded and can be fully customized to | ||||||||||||||||||||||||||||||||||||||
| 62 | the benchmarks that better suit your own scenario. | ||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | The only non-CPAN libraries required to install/run the suite are libdb, libjpeg | ||||||||||||||||||||||||||||||||||||||
| 65 | (with headers). There are a few prerequisite CPAN libraries, plus an optional one | ||||||||||||||||||||||||||||||||||||||
| 66 | (L<BioPerl>, requires libxml on system) which enables extra benchmarks. | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | =head1 SCRIPTS | ||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||
| 70 | You should only ever need the main script C<dkbench> for the benchmark suite, and, | ||||||||||||||||||||||||||||||||||||||
| 71 | perhaps C<setup_dkbench> can help with setup or standardizing/normalizing your | ||||||||||||||||||||||||||||||||||||||
| 72 | benchmarking environment. | ||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||
| 74 | =head2 C<dkbench> | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | The main script that runs the DKbench benchmark suite. If L<BioPerl> is installed, | ||||||||||||||||||||||||||||||||||||||
| 77 | you may want to start your first run with C<dkbench --setup>. Otherwise, there are | ||||||||||||||||||||||||||||||||||||||
| 78 | many options to control number of threads, iterations, which benchmarks to run etc: | ||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | dkbench [options] | ||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | Options: | ||||||||||||||||||||||||||||||||||||||
| 83 | --threads <i>, -j <i> : Number of benchmark threads (default is 1). | ||||||||||||||||||||||||||||||||||||||
| 84 | --multi, -m : Multi-threaded using all your CPU cores/threads. | ||||||||||||||||||||||||||||||||||||||
| 85 | --iter <i>, -i <i> : Number of suite iterations (with min/max/avg at the end). | ||||||||||||||||||||||||||||||||||||||
| 86 | --include <regex> : Run only benchmarks that match regex. | ||||||||||||||||||||||||||||||||||||||
| 87 | --exclude <regex> : Do not run benchmarks that match regex. | ||||||||||||||||||||||||||||||||||||||
| 88 | --time, -t : Report time (sec) instead of score. | ||||||||||||||||||||||||||||||||||||||
| 89 | --quick, -q : Quick benchmark run (implies -t). | ||||||||||||||||||||||||||||||||||||||
| 90 | --no_mce : Do not run under MCE::Loop (implies -j 1). | ||||||||||||||||||||||||||||||||||||||
| 91 | --skip_bio : Skip BioPerl benchmarks. | ||||||||||||||||||||||||||||||||||||||
| 92 | --skip_timep : Skip Time::Piece benchmark (see benchmark details on why). | ||||||||||||||||||||||||||||||||||||||
| 93 | --skip_prove : Skip Moose prove benchmark. | ||||||||||||||||||||||||||||||||||||||
| 94 | --bio_codons : Run optional BioPerl Codons benchmark (does not scale well). | ||||||||||||||||||||||||||||||||||||||
| 95 | --sleep <i> : Sleep for <i> secs after each benchmark. | ||||||||||||||||||||||||||||||||||||||
| 96 | --setup : Download the Genbank data to enable the BioPerl tests. | ||||||||||||||||||||||||||||||||||||||
| 97 | --datapath <path> : Override the path where the expected benchmark data is found. | ||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | The default run (no options) will run all the benchmarks both single-threaded and | ||||||||||||||||||||||||||||||||||||||
| 100 | multi-threaded (using all detected CPU cores/hyperthreads) and show you scores and | ||||||||||||||||||||||||||||||||||||||
| 101 | multi vs single threaded scalability. | ||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | The scores are such that a reference CPU (Intel Xeon Platinum 8481C - Sapphire Rapids) | ||||||||||||||||||||||||||||||||||||||
| 104 | would get 1000 on a single core benchmark run using the default software configuration | ||||||||||||||||||||||||||||||||||||||
| 105 | (Linux/Perl 5.36.0/ref CPAN modules). | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | The multi-thread scalability should approach 100% if each thread runs on a full core | ||||||||||||||||||||||||||||||||||||||
| 108 | (i.e. no SMT), and the core can maintain the clock speed it had on the single-thread | ||||||||||||||||||||||||||||||||||||||
| 109 | runs. Note that the overall scalability is an average of the benchmarks that drops | ||||||||||||||||||||||||||||||||||||||
| 110 | non-scaling outliers (over 2*stdev less than the mean). | ||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | The suite will report a Pass/Fail per benchmark. A failure may be caused if you have | ||||||||||||||||||||||||||||||||||||||
| 113 | different CPAN module version installed - this is normal, and you will be warned. | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | The suite uses L<MCE::Loop> to run on the desired number of parallel threads, although | ||||||||||||||||||||||||||||||||||||||
| 116 | there is an option to disable it, which forces a single-thread run. | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | =head2 C<setup_dkbench> | ||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||
| 120 | Simple installer to check/get the reference versions of CPAN modules and download | ||||||||||||||||||||||||||||||||||||||
| 121 | the Genbank data file required for the BioPerl benchmarks of the DKbench suite. | ||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | It assumes that you have some software already installed (e.g. C<cpanm>), try | ||||||||||||||||||||||||||||||||||||||
| 124 | C<setup_dkbench --help> for more details on that. | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | setup_dkbench [--force --sudo --test --data=s --help] | ||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | Options: | ||||||||||||||||||||||||||||||||||||||
| 129 | --sudo : Will use sudo for cpanm calls. | ||||||||||||||||||||||||||||||||||||||
| 130 | --force : Will install reference CPAN module versions and re-download the genbank data. | ||||||||||||||||||||||||||||||||||||||
| 131 | --test : Will run the test suites for the CPAN module (default behaviour is to skip). | ||||||||||||||||||||||||||||||||||||||
| 132 | --data=s : Data dir path to copy files from. Should not need if you installed DKbench. | ||||||||||||||||||||||||||||||||||||||
| 133 | --help : Print this help text and exit. | ||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||
| 135 | Running it without any options will fetch the data for the BioPerl tests (similar to | ||||||||||||||||||||||||||||||||||||||
| 136 | C<dkbench --setup>) and use C<cpanm> to install any missing libraries. | ||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||
| 138 | Using it with C<--force> will install the reference CPAN module versions, including | ||||||||||||||||||||||||||||||||||||||
| 139 | BioPerl which is not a requirement for DKbench, but enables the BioPerl benchmarks. | ||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | The reference CPAN versions are suggested if you want a fair comparison between | ||||||||||||||||||||||||||||||||||||||
| 142 | systems and also for the benchmark Pass/Fail results to be reliable. | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | =head1 BENCHMARKS | ||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||
| 146 | The suite consists of 19 benchmarks. With a successful installation of the DKbench | ||||||||||||||||||||||||||||||||||||||
| 147 | package, 18 will run by default, although the C<BioPerl Monomers> requires BioPerl | ||||||||||||||||||||||||||||||||||||||
| 148 | to be installed and Genbank data to be downloaded (C<dkbench --setup> can do the | ||||||||||||||||||||||||||||||||||||||
| 149 | latter). | ||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | On MacOS only, the C<Time::Piece> benchmark will be skipped, unless you try a single | ||||||||||||||||||||||||||||||||||||||
| 152 | thread run without MCE (C<--skip_mce>). | ||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||
| 154 | =over 4 | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | =item * C<Astro> : Calculates precession between random epochs and finds the | ||||||||||||||||||||||||||||||||||||||
| 157 | constellation for random equatorial coordinates using L<Astro::Coord::Precession> | ||||||||||||||||||||||||||||||||||||||
| 158 | and L<Astro::Coord::Constellations> respectively. | ||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | =item * C<BioPerl Codons> : Counts codons on a sample bacterial sequence. Requires | ||||||||||||||||||||||||||||||||||||||
| 161 | L<BioPerl> to be installed. | ||||||||||||||||||||||||||||||||||||||
| 162 | This test does not scale well on multiple threads, so is disabled by default (use | ||||||||||||||||||||||||||||||||||||||
| 163 | C<--bio_codons>) option. Requires data fetched using the C<--setup> option. | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | =item * C<BioPerl Monomers> : Counts monomers on 500 sample bacterial sequences using | ||||||||||||||||||||||||||||||||||||||
| 166 | L<BioPerl> (which needs to be installed). Requires data fetched using the C<--setup> | ||||||||||||||||||||||||||||||||||||||
| 167 | option. | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | =item * C<CSS::Inliner> : Inlines CSS on 2 sample wiki pages using L<CSS::Inliner>. | ||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||
| 171 | =item * C<Crypt::JWT> : Creates large JSON Web Tokens with RSA and EC crypto keys | ||||||||||||||||||||||||||||||||||||||
| 172 | using L<Crypt::JWT>. | ||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | =item * C<DateTime> : Creates and manipulates L<DateTime> objects. | ||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||
| 176 | =item * C<Digest> : Creates MD5, SH1 and SHA-512 digests of a large string. | ||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||
| 178 | =item * C<Encode> : Encodes/decodes large strings from/to UTF-8/16, cp-1252. | ||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||
| 180 | =item * C<HTML::FormatText> : Converts HTML to text for 2 sample wiki pages using | ||||||||||||||||||||||||||||||||||||||
| 181 | L<HTML::FormatText>. | ||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||
| 183 | =item * C<Imager> : Loads a sample image and performs edits/manipulations with | ||||||||||||||||||||||||||||||||||||||
| 184 | L<Imager>, including filters like gaussian, unsharp mask, mandelbrot. | ||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | =item * C<JSON::XS> : Encodes/decodes random data structures to/from JSON using | ||||||||||||||||||||||||||||||||||||||
| 187 | L<JSON::XS>. | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | =item * C<Math::DCT> : Does 8x8, 18x18 and 32x32 DCT transforms with L<Math::DCT>. | ||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||
| 191 | =item * C<Math::MatrixReal> : Performs various manipulations on L<Math::MatrixReal> | ||||||||||||||||||||||||||||||||||||||
| 192 | matrices. | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | =item * C<Moose> : Creates L<Moose> objects. | ||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||
| 196 | =item * C<Moose prove> : Runs 110 tests from the Moose 2.2201 test suite. The least | ||||||||||||||||||||||||||||||||||||||
| 197 | CPU-intensive test, most of the time will be spent loading the interpreter and | ||||||||||||||||||||||||||||||||||||||
| 198 | the Moose module for each test, which is behaviour representative of how a Perl | ||||||||||||||||||||||||||||||||||||||
| 199 | test suite runs by default. | ||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||
| 201 | =item * C<Primes> : Calculates all primes up to 7.5 million. Small number with | ||||||||||||||||||||||||||||||||||||||
| 202 | repeat was chosen to keep low memory (this is a pure Perl function no Math libraries). | ||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||
| 204 | =item * C<Regex/Subst> : Concatenates 3 wiki pages into a byte string then matches | ||||||||||||||||||||||||||||||||||||||
| 205 | 3 typical regexes (for names, emails, URIs), replaces html tags with their contents | ||||||||||||||||||||||||||||||||||||||
| 206 | (starting with the innermost) and does calls subst a few times. | ||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||
| 208 | =item * C<Regex/Subst utf8> : Exactly the same as C<Regex/Subst>, but reads into | ||||||||||||||||||||||||||||||||||||||
| 209 | a utf8 string. Perl version can make a big difference, as Unicode behaviour has | ||||||||||||||||||||||||||||||||||||||
| 210 | changed (old Perl versions are faster but less strict in general). | ||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | =item * C<Time::Piece> : Creates and manipulates/converts Time::Piece objects. It | ||||||||||||||||||||||||||||||||||||||
| 213 | is disabled by default on MacOS (unless C<--no_mce> is specified), as it runs | ||||||||||||||||||||||||||||||||||||||
| 214 | extremely slow when forked on this platform. In general you may want to skip this | ||||||||||||||||||||||||||||||||||||||
| 215 | benchmark (C<--skip_timep>) if you are comparing different OS platforms. | ||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||
| 217 | =back | ||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||
| 219 | =head1 EXPORTED FUNCTIONS | ||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||
| 221 | You will normally not use the Benchmark::DKbench module itself, but here are the | ||||||||||||||||||||||||||||||||||||||
| 222 | exported functions that the C<dkbench> script uses for reference: | ||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||
| 224 | =head2 C<system_identity> | ||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | my $cores = system_identity(); | ||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||
| 228 | Prints out software/hardware configuration and returns then number of cores detected. | ||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||
| 230 | =head2 C<suite_run> | ||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||
| 232 | my %stats = suite_run(\%options); | ||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||
| 234 | Runs the benchmark suite given the C<%options> and prints results. Returns a hash | ||||||||||||||||||||||||||||||||||||||
| 235 | with run stats. | ||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||
| 237 | =head2 C<calc_scalability> | ||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||
| 239 | calc_scalability(\%options, \%stat_single, \%stat_multi); | ||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||
| 241 | Given the C<%stat_single> results of a single-threaded C<suite_run> and C<%stat_multi> | ||||||||||||||||||||||||||||||||||||||
| 242 | results of a multi-threaded run, will calculate and print the multi-thread scalability. | ||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||
| 244 | =head1 NOTES | ||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | The benchmark suite was created to compare the performance of various cloud offerings. | ||||||||||||||||||||||||||||||||||||||
| 247 | You can see the L<original perl blog post|http://blogs.perl.org/users/dimitrios_kechagias/2022/03/cloud-provider-performance-comparison-gcp-aws-azure-perl.html> | ||||||||||||||||||||||||||||||||||||||
| 248 | as well as the L<2023 follow-up|https://dev.to/dkechag/cloud-vm-performance-value-comparison-2023-perl-more-1kpp>. | ||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | The benchmarks for the first version were more tuned to what I would expect to run | ||||||||||||||||||||||||||||||||||||||
| 251 | on the servers I was testing, to choose the optimal types for the company I was | ||||||||||||||||||||||||||||||||||||||
| 252 | working for. The second version has expanded a bit over that and is friendlier to | ||||||||||||||||||||||||||||||||||||||
| 253 | use. | ||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||
| 255 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||
| 257 | Dimitrios Kechagias, C<< <dkechag at cpan.org> >> | ||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | Please report any bugs or feature requests either on L<GitHub|https://github.com/dkechag/Benchmark-DKbench> (preferred), or on RT (via the email | ||||||||||||||||||||||||||||||||||||||
| 262 | C<bug-Benchmark-DKbench at rt.cpan.org> or L<web interface|https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Benchmark-DKbench>). | ||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||
| 264 | I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||
| 266 | =head1 GIT | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | L<https://github.com/dkechag/Benchmark-DKbench> | ||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||
| 270 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||
| 272 | This software is copyright (c) 2021-2023 by Dimitrios Kechagias. | ||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||
| 274 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||
| 275 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||
| 277 | =cut | ||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||
| 279 | sub benchmark_list { | ||||||||||||||||||||||||||||||||||||||
| 280 | return { # idx : 0 = result, 1 = ref time, 2 = func, 3 = quick test, 4 = normal test | ||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | 'Astro' => ['e71c7ae08f16fe26aea7cfdb72785873', 5.674, \&bench_astro, 20000, 80000], | ||||||||||||||||||||||||||||||||||||
|
Subroutine
benchmark_list: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 282 | 'BioPerl Codons' => ['97c443c099886ca60e99f7ab9df689b5', 8.752, \&bench_bioperl_codons, 3, 5, 1], | ||||||||||||||||||||||||||||||||||||||
| 283 | 'BioPerl Monomers' => ['d29ed0a5c205c803c112be1338d1f060', 5.241, \&bench_bioperl_mono, 6, 20], | ||||||||||||||||||||||||||||||||||||||
| 284 | 'Crypt::JWT' => ['d41d8cd98f00b204e9800998ecf8427e', 6.451, \&bench_jwt, 250, 900], | ||||||||||||||||||||||||||||||||||||||
| 285 | 'CSS::Inliner' => ['82c1b6de9ca0500a48f8a8df0998df3c', 4.603, \&bench_css, 2, 5], | ||||||||||||||||||||||||||||||||||||||
| 286 | 'DateTime' => ['b08d2eeb994083b7422f6c9d86fed2c6', 6.198, \&bench_datetime, 5000, 15000], | ||||||||||||||||||||||||||||||||||||||
| 287 | 'Digest' => ['4b69f6cf0f53cbf6c3444f2f767dd21d', 4.513, \&bench_digest, 50, 250], | ||||||||||||||||||||||||||||||||||||||
| 288 | 'Encode' => ['PASS 1025', 5.725, \&bench_encode, 40, 120], | ||||||||||||||||||||||||||||||||||||||
| 289 | 'HTML::FormatText' => ['8c2589f0a5276252805e11301fc2ab56', 4.756, \&bench_formattext, 4, 10], | ||||||||||||||||||||||||||||||||||||||
| 290 | 'Imager' => ['8829cb3703e884054eb025496f336c63', 6.783, \&bench_imager, 4, 16], | ||||||||||||||||||||||||||||||||||||||
| 291 | 'JSON::XS' => ['PASS', 5.388, \&bench_json, 600, 2200], | ||||||||||||||||||||||||||||||||||||||
| 292 | 'Math::DCT' => ['766e3bfd7a2276f452bb3d1bd21939bc', 7.147, \&bench_dct, 25000, 100_000], | ||||||||||||||||||||||||||||||||||||||
| 293 | 'Math::MatrixReal' => ['4606231b1309fb21ae1223fa0043fd76', 4.293, \&bench_matrixreal, 200, 650], | ||||||||||||||||||||||||||||||||||||||
| 294 | 'Moose' => ['d1cb92c513f6378506dfa11f694cffac', 4.968, \&bench_moose, 10_000, 30_000], | ||||||||||||||||||||||||||||||||||||||
| 295 | 'Moose prove' => ['PASS', 7.974, \&bench_moose_prv, 0.5, 1], | ||||||||||||||||||||||||||||||||||||||
| 296 | 'Primes' => ['4266f70a7a9efb3484cf5d98eba32244', 3.680, \&bench_primes_m, 2, 5], | ||||||||||||||||||||||||||||||||||||||
| 297 | 'Regex/Subst' => ['30ce365b25f3d597578b3bdb14aa3f57', 4.652, \&bench_regex_asc, 8, 24], | ||||||||||||||||||||||||||||||||||||||
| 298 | 'Regex/Subst utf8' => ['857eb4e63a4d174ca4a16fe678f7626f', 5.703, \&bench_regex_utf8, 3, 10], | ||||||||||||||||||||||||||||||||||||||
| 299 | 'Time::Piece' => ['5d393b000a42a626bad7208f8be4121e', 5.907, \&bench_timepiece, 75_000, 275_000], | ||||||||||||||||||||||||||||||||||||||
| 300 | }; | ||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||
| 303 | sub system_identity { | ||||||||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | my $info = Sys::Info->new; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
system_identity: called CC=14 SCAR=32.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my $cpu = $info->device( 'CPU' ); | |||||||||||||||||||||||||||||||||||||
| 306 | 1 | my @data = $cpu->identify; | |||||||||||||||||||||||||||||||||||||
| 307 | 1 | ▶ | my $speed = $cpu->speed ? " @ ".(int($cpu->speed+0.5))."MHz" : ''; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 308 | 1 | ▶ | my $cores = $cpu->count || 1; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$cpu->count || 1
MC/DC0%0/1
$cpu->count || 1
$cpu->count
Truth table50%1/2
A
A= $cpu->count
| |||||||||||||||||||||||||||||||||||||||
| 309 | 1 | ▶ | my $ht = $cpu->ht ? $cpu->ht == $cores ? " (h-threads)" : " (".$cpu->ht." threads)" : ''; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 310 | 1 | ▶ | my $arch = $data[0]->{architecture} ? " ($data[0]->{architecture})" : ''; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 311 | 1 | ▶ | my $model = $data[0]->{chip_name} || $data[0]->{name} || $data[0]->{model} || 'Unknown'; | ||||||||||||||||||||||||||||||||||||
|
Condition37%3/8
$data[0]{'chip_name'} || $data[0]{'name'} || $data[0]{'model'} || 'Unknown'
$data[0]{"chip_name"} or $data[0]{"name"} or $data[0]{"model"}
$data[0]{"chip_name"} or $data[0]{"name"}
MC/DC0%0/3
$data[0]{'chip_name'} || $data[0]{'name'} || $data[0]{'model'} || 'Unknown'
$data[0]{"chip_name"}
$data[0]{"name"}
$data[0]{"model"}
Truth table25%1/4
A or B or C
A= $data[0]{"chip_name"}B= $data[0]{"name"}C= $data[0]{"model"}
| |||||||||||||||||||||||||||||||||||||||
| 312 | 1 | my $os = $info->os; | |||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | my $osn = eval{$os->name(long => 1)} || $^O; | ||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval { || $^O
MC/DC0%0/2
eval {
do {
$os->name('long', 1)
}
} || $^O
eval {
do {
$os->name('long', 1)
}
}
$^O
Truth table33%1/3
A || B
A= eval {
do {
$os->name('long', 1)
}
}B= $^O
| |||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ▶ | if ($^O =~ /darwin/ && $model =~ /^Mac|Unknown/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$^O =~ /darwin/ and $model =~ /^Mac|Unknown/
MC/DC0%0/2
$^O =~ /darwin/ and $model =~ /^Mac|Unknown/
$^O =~ /darwin/
$model =~ /^Mac|Unknown/
Truth table33%1/3
A and B
A= $^O =~ /darwin/B= $model =~ /^Mac|Unknown/
| |||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $brand = `sysctl -a |grep brand`; | |||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | if ($brand =~ /brand_string: (.*)/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $model = $1; | |||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||
| 320 | 1 | ▶ | $speed = '' if $model =~ /@|GHz|MHz/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||
| 322 | 1 | print "------------ Software ------------\nDKbench v$VERSION\n"; | |||||||||||||||||||||||||||||||||||||
| 323 | 1 | print "Perl $^V\n"; | |||||||||||||||||||||||||||||||||||||
| 324 | 1 | print "OS: $osn\n------------ Hardware ------------\n"; | |||||||||||||||||||||||||||||||||||||
| 325 | 1 | print "CPU type: $model$speed$arch\n"; | |||||||||||||||||||||||||||||||||||||
| 326 | 1 | print "Cores: $cores$ht\n".("-"x34)."\n"; | |||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||
| 328 | 1 | return $cores; | |||||||||||||||||||||||||||||||||||||
| 329 | }; | ||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||
| 331 | sub suite_run { | ||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | my $opt = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
suite_run: called CC=8 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | $datadir = $opt->{datapath} if $opt->{datapath}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 334 | 2 | ▶ | $opt->{threads} //= 1; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt->{"threads"} //= 1
MC/DC0%0/1
$opt->{"threads"} //= 1
$opt->{"threads"}
Truth table50%1/2
A
A= $opt->{"threads"}
| |||||||||||||||||||||||||||||||||||||||
| 335 | 2 | ▶ | $opt->{repeat} //= 1; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt->{"repeat"} //= 1
MC/DC0%0/1
$opt->{"repeat"} //= 1
$opt->{"repeat"}
Truth table50%1/2
A
A= $opt->{"repeat"}
| |||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | $opt->{f} = $opt->{time} ? '%.3f' : '%5.0f'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 337 | 2 | my %stats = (threads => $opt->{threads}); | |||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||
| 339 | MCE::Loop::init { | ||||||||||||||||||||||||||||||||||||||
| 340 | max_workers => $opt->{threads}, | ||||||||||||||||||||||||||||||||||||||
| 341 | 2 | chunk_size => 1, | |||||||||||||||||||||||||||||||||||||
| 342 | }; | ||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||
| 344 | 2 | foreach (1..$opt->{iter}) { | |||||||||||||||||||||||||||||||||||||
| 345 | 2 | ▶ | print "Iteration $_ of $opt->{iter}...\n" if $opt->{iter} > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 346 | 2 | run_iteration($opt, \%stats); | |||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | total_stats($opt, \%stats) if $opt->{iter} > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||
| 351 | 0 | return %stats; | |||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||
| 354 | sub calc_scalability { | ||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | my ($opt, $stats1, $stats2) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
calc_scalability: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 356 | 0 | my $benchmarks = benchmark_list(); | |||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $threads = $stats2->{threads}/$stats1->{threads}; | |||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $display = $opt->{time} ? 'times' : 'scores'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $opt->{f} = $opt->{time} ? '%.3f' : '%5.0f'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my (@perf, @scal); | |||||||||||||||||||||||||||||||||||||
| 361 | 0 | print "Multi thread Scalability:\n".pad_to("Benchmark",24).pad_to("Multi perf xSingle",24).pad_to("Multi scalability %",24); | |||||||||||||||||||||||||||||||||||||
| 362 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||
| 363 | 0 | foreach my $bench (sort keys %$benchmarks) { | |||||||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | next unless $stats1->{$bench}->{times} && $stats2->{$bench}->{times}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$stats1->{$bench}{"times"} and $stats2->{$bench}{"times"}
MC/DC0%0/2
$stats1->{$bench}{"times"} and $stats2->{$bench}{"times"}
$stats1->{$bench}{"times"}
$stats2->{$bench}{"times"}
Truth table0%0/3
A and B
A= $stats1->{$bench}{"times"}B= $stats2->{$bench}{"times"}
| |||||||||||||||||||||||||||||||||||||||
| 365 | 0 | my @res1 = min_max_avg($stats1->{$bench}->{times}); | |||||||||||||||||||||||||||||||||||||
| 366 | 0 | my @res2 = min_max_avg($stats2->{$bench}->{times}); | |||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | push @perf, $res1[2]/$res2[2]*$threads if $res2[2]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | push @scal, $res1[2]/$res2[2]*100 if $res2[2]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 369 | 0 | print pad_to("$bench:",24).pad_to(sprintf("%.2f",$perf[-1]),24).pad_to(sprintf("%2.0f",$scal[-1]),24)."\n"; | |||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||
| 371 | 0 | print (("-"x34)."\n"); | |||||||||||||||||||||||||||||||||||||
| 372 | 0 | my ($avg1) = min_max_avg($stats1->{total}->{$display}); | |||||||||||||||||||||||||||||||||||||
| 373 | 0 | my ($avg2) = min_max_avg($stats2->{total}->{$display}); | |||||||||||||||||||||||||||||||||||||
| 374 | 0 | print "DKbench summary:\n"; | |||||||||||||||||||||||||||||||||||||
| 375 | 0 | print pad_to("Single:").sprintf($opt->{f}, $avg1)."\n"; | |||||||||||||||||||||||||||||||||||||
| 376 | 0 | print pad_to("Multi:").sprintf($opt->{f}, $avg2)."\n"; | |||||||||||||||||||||||||||||||||||||
| 377 | 0 | my @newperf = Benchmark::DKbench::drop_outliers(\@perf, -1); | |||||||||||||||||||||||||||||||||||||
| 378 | 0 | my @newscal = Benchmark::DKbench::drop_outliers(\@scal, -1); | |||||||||||||||||||||||||||||||||||||
| 379 | 0 | @perf = min_max_avg(\@newperf); | |||||||||||||||||||||||||||||||||||||
| 380 | 0 | @scal = min_max_avg(\@newscal); | |||||||||||||||||||||||||||||||||||||
| 381 | 0 | print pad_to("Multi/Single perf:").sprintf("%.2fx\t(%.2f - %.2f)", $perf[2], $perf[0], $perf[1])."\n"; | |||||||||||||||||||||||||||||||||||||
| 382 | 0 | print pad_to("Multi scalability:").sprintf("%2.1f%% \t(%.0f%% - %.0f%%)", $scal[2], $scal[0], $scal[1])."\n"; | |||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||
| 385 | sub run_iteration { | ||||||||||||||||||||||||||||||||||||||
| 386 | 2 | ▶ | my ($opt, $stats) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run_iteration: called CC=24 SCAR=36.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 387 | 2 | my $benchmarks = benchmark_list(); | |||||||||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | my $title = $opt->{time} ? 'Time (sec)' : 'Score'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 389 | 2 | print pad_to("Benchmark").pad_to($title); | |||||||||||||||||||||||||||||||||||||
| 390 | 2 | ▶ | print "Pass/Fail" unless $opt->{time}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 391 | 2 | print "\n"; | |||||||||||||||||||||||||||||||||||||
| 392 | 2 | my ($total_score, $total_time, $i) = (0, 0, 0); | |||||||||||||||||||||||||||||||||||||
| 393 | 2 | foreach my $bench (sort keys %$benchmarks) { | |||||||||||||||||||||||||||||||||||||
| 394 | 24 | ▶ | next if $opt->{skip_bio} && $bench =~ /Monomers/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt->{"skip_bio"} and $bench =~ /Monomers/
MC/DC100%2/2
$opt->{"skip_bio"} and $bench =~ /Monomers/
$opt->{"skip_bio"}
$bench =~ /Monomers/
Truth table100%3/3
A and B
A= $opt->{"skip_bio"}B= $bench =~ /Monomers/
| |||||||||||||||||||||||||||||||||||||||
| 395 | 23 | ▶ | next if $opt->{skip_prove} && $bench =~ /prove/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"skip_prove"} and $bench =~ /prove/
MC/DC0%0/2
$opt->{"skip_prove"} and $bench =~ /prove/
$opt->{"skip_prove"}
$bench =~ /prove/
Truth table33%1/3
A and B
A= $opt->{"skip_prove"}B= $bench =~ /prove/
| |||||||||||||||||||||||||||||||||||||||
| 396 | 23 | ▶ | next if !$opt->{bio_codons} && $bench =~ /Codons/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $opt->{"bio_codons"} and $bench =~ /Codons/
MC/DC50%1/2
not $opt->{"bio_codons"} and $bench =~ /Codons/
not $opt->{"bio_codons"}
$bench =~ /Codons/
Truth table66%2/3
not(A) and B
A= not $opt->{"bio_codons"}B= $bench =~ /Codons/
| |||||||||||||||||||||||||||||||||||||||
| 397 | 21 | ▶ | next if $opt->{skip_timep} && $bench =~ /Time::Piece/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt->{"skip_timep"} and $bench =~ /Time::Piece/
MC/DC0%0/2
$opt->{"skip_timep"} and $bench =~ /Time::Piece/
$opt->{"skip_timep"}
$bench =~ /Time::Piece/
Truth table33%1/3
A and B
A= $opt->{"skip_timep"}B= $bench =~ /Time::Piece/
| |||||||||||||||||||||||||||||||||||||||
| 398 | 21 | ▶ | next if $opt->{exclude} && $bench =~ /$opt->{exclude}/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"exclude"} and $bench =~ /$opt->{"exclude"}/
MC/DC50%1/2
$opt->{"exclude"} and $bench =~ /$opt->{"exclude"}/
$opt->{"exclude"}
$bench =~ /$opt->{"exclude"}/
Truth table66%2/3
A and B
A= $opt->{"exclude"}B= $bench =~ /$opt->{"exclude"}/
| |||||||||||||||||||||||||||||||||||||||
| 399 | 19 | ▶ | next if $opt->{include} && $bench !~ /$opt->{include}/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt->{"include"} and not $bench =~ /$opt->{"include"}/
MC/DC50%1/2
$opt->{"include"} and not $bench =~ /$opt->{"include"}/
$opt->{"include"}
not $bench =~ /$opt->{"include"}/
Truth table66%2/3
A and not(B)
A= $opt->{"include"}B= not $bench =~ /$opt->{"include"}/
| |||||||||||||||||||||||||||||||||||||||
| 400 | 3 | ▶ | if ($bench =~ /Bio/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 401 | 0 | require Bio::SeqIO; | |||||||||||||||||||||||||||||||||||||
| 402 | 0 | require Bio::Tools::SeqStats; | |||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||
| 404 | 3 | my ($time, $res) = mce_bench_run($opt, $benchmarks->{$bench}); | |||||||||||||||||||||||||||||||||||||
| 405 | 2 | ▶ | my $score = int(1000*$opt->{threads}*$benchmarks->{$bench}->[1]/($time || 1)+0.5); | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$time || 1
MC/DC0%0/1
$time || 1
$time
Truth table50%1/2
A
A= $time
| |||||||||||||||||||||||||||||||||||||||
| 406 | 2 | $total_score += $score; | |||||||||||||||||||||||||||||||||||||
| 407 | 2 | $total_time += $time; | |||||||||||||||||||||||||||||||||||||
| 408 | 2 | $i++; | |||||||||||||||||||||||||||||||||||||
| 409 | 2 | push @{$stats->{$bench}->{times}}, $time; | |||||||||||||||||||||||||||||||||||||
| 410 | 2 | push @{$stats->{$bench}->{scores}}, $score; | |||||||||||||||||||||||||||||||||||||
| 411 | 2 | ▶ | my $d = $stats->{$bench}->{$opt->{time} ? 'times' : 'scores'}->[-1]; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 412 | 2 | ▶ | $stats->{$bench}->{fail}++ if $res ne 'Pass'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 413 | 2 | print pad_to("$bench:").pad_to(sprintf($opt->{f}, $d)); | |||||||||||||||||||||||||||||||||||||
| 414 | 2 | ▶ | print "$res" unless $opt->{time}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 415 | 2 | print "\n"; | |||||||||||||||||||||||||||||||||||||
| 416 | 2 | ▶ | sleep $opt->{sleep} if $opt->{sleep}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | die "No tests to run\n" unless $i; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my $s = int($total_score/$i+0.5); | |||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | print pad_to("Overall $title: ").sprintf($opt->{f}."\n", $opt->{time} ? $total_time : $s); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 421 | 0 | push @{$stats->{total}->{times}}, $total_time; | |||||||||||||||||||||||||||||||||||||
| 422 | 0 | push @{$stats->{total}->{scores}}, $s; | |||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||
| 425 | sub mce_bench_run { | ||||||||||||||||||||||||||||||||||||||
| 426 | 3 | ▶ | my $opt = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
mce_bench_run: called CC=6 SCAR=30.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 427 | 3 | my $benchmark = shift; | |||||||||||||||||||||||||||||||||||||
| 428 | 3 | ▶ | $benchmark->[3] = $benchmark->[4] unless $opt->{quick}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 429 | 3 | ▶ | return bench_run($benchmark) if $opt->{no_mce}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||
| 431 | my @stats = mce_loop { | ||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | my ($mce, $chunk_ref, $chunk_id) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 433 | 0 | for (@{$chunk_ref}) { | |||||||||||||||||||||||||||||||||||||
| 434 | 0 | my ($time, $res) = bench_run($benchmark); | |||||||||||||||||||||||||||||||||||||
| 435 | 0 | MCE->gather([$time, $res]); | |||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||
| 438 | 0 | (1 .. $opt->{threads} * $opt->{repeat}); | |||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my ($res, $time) = ('Pass', 0); | |||||||||||||||||||||||||||||||||||||
| 441 | 0 | foreach (@stats) { | |||||||||||||||||||||||||||||||||||||
| 442 | 0 | $time += $_->[0]; | |||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | $res = $_->[1] if $_->[1] ne 'Pass'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | return $time/($opt->{threads}*$opt->{repeat} || 1), $res; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt->{'threads'} * $opt->{'repeat'} || 1
MC/DC0%0/1
$opt->{'threads'} * $opt->{'repeat'} || 1
$opt->{'threads'} * $opt->{'repeat'}
Truth table0%0/2
A
A= $opt->{'threads'} * $opt->{'repeat'}
| |||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||
| 449 | sub bench_run { | ||||||||||||||||||||||||||||||||||||||
| 450 | 4 | ▶ | my ($benchmark, $srand) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_run: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 451 | 4 | ▶ | $srand //= 1; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$srand //= 1
MC/DC100%1/1
$srand //= 1
$srand
Truth table100%2/2
A
A= $srand
| |||||||||||||||||||||||||||||||||||||||
| 452 | 4 | srand($srand); # For repeatability | |||||||||||||||||||||||||||||||||||||
| 453 | 4 | my $t0 = Time::HiRes::time(); | |||||||||||||||||||||||||||||||||||||
| 454 | 4 | my $out = $benchmark->[2]->($benchmark->[3]); | |||||||||||||||||||||||||||||||||||||
| 455 | 2 | my $time = sprintf("%.3f", Time::HiRes::time()-$t0); | |||||||||||||||||||||||||||||||||||||
| 456 | 2 | ▶ | my $r = $out eq $benchmark->[0] ? 'Pass' : "Fail ($out)"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 457 | 2 | return $time, $r; | |||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||
| 460 | sub bench_astro { | ||||||||||||||||||||||||||||||||||||||
| 461 | 1 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_astro: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 462 | 1 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 463 | my $precessed = precess([rand(24), rand(180)-90], rand(200)+1900, rand(200)+1900) | ||||||||||||||||||||||||||||||||||||||
| 464 | 1 | for (1..$iter*10); | |||||||||||||||||||||||||||||||||||||
| 465 | 1 | my $constellation_abbrev; | |||||||||||||||||||||||||||||||||||||
| 466 | $d->add(constellation_for_eq(rand(24), rand(180)-90, rand(200)+1900)) | ||||||||||||||||||||||||||||||||||||||
| 467 | 1 | for (1..$iter); | |||||||||||||||||||||||||||||||||||||
| 468 | 1 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||
| 471 | sub bench_bioperl_codons { | ||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | my $skip = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_bioperl_codons: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||
| 474 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $file = catfile($datadir, "gbbct5.seq"); | |||||||||||||||||||||||||||||||||||||
| 476 | 0 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 477 | 0 | my $in = Bio::SeqIO->new(-file => $file, -format => "genbank"); | |||||||||||||||||||||||||||||||||||||
| 478 | 0 | $in->next_seq for (1..$skip); | |||||||||||||||||||||||||||||||||||||
| 479 | 0 | my $seq = $in->next_seq; | |||||||||||||||||||||||||||||||||||||
| 480 | 0 | my $seq_stats = Bio::Tools::SeqStats->new($seq); | |||||||||||||||||||||||||||||||||||||
| 481 | 0 | my $codon_ref = $seq_stats->count_codons(); | |||||||||||||||||||||||||||||||||||||
| 482 | 0 | $d->add($_, $codon_ref->{$_}) for sort keys %$codon_ref; | |||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||
| 484 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||
| 487 | sub bench_bioperl_mono { | ||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_bioperl_mono: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $file = catfile($datadir, "gbbct5.seq"); | |||||||||||||||||||||||||||||||||||||
| 490 | 0 | my $in = Bio::SeqIO->new(-file => $file, -format => "genbank"); | |||||||||||||||||||||||||||||||||||||
| 491 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $builder = $in->sequence_builder(); | |||||||||||||||||||||||||||||||||||||
| 493 | 0 | $builder->want_none(); | |||||||||||||||||||||||||||||||||||||
| 494 | 0 | $builder->add_wanted_slot('display_id','seq'); | |||||||||||||||||||||||||||||||||||||
| 495 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $seq = $in->next_seq; | |||||||||||||||||||||||||||||||||||||
| 497 | 0 | my $seq_stats = Bio::Tools::SeqStats->new($seq); | |||||||||||||||||||||||||||||||||||||
| 498 | 0 | my $weight = $seq_stats->get_mol_wt(); | |||||||||||||||||||||||||||||||||||||
| 499 | 0 | $d->add(int($weight->[0])); | |||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $monomer_ref = $seq_stats->count_monomers(); | |||||||||||||||||||||||||||||||||||||
| 501 | 0 | $d->add($_, $monomer_ref->{$_}) for sort keys %$monomer_ref; | |||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||
| 503 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||
| 506 | sub bench_css { | ||||||||||||||||||||||||||||||||||||||
| 507 | 1 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_css: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 508 | 1 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 509 | 1 | my $file; | |||||||||||||||||||||||||||||||||||||
| 510 | my $html; | ||||||||||||||||||||||||||||||||||||||
| 511 | 1 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 512 | 2 | my $inliner = new CSS::Inliner(); | |||||||||||||||||||||||||||||||||||||
| 513 | 2 | my $i = $_ % 2 + 1; | |||||||||||||||||||||||||||||||||||||
| 514 | 2 | $file = catfile($datadir, "wiki$i.html"); | |||||||||||||||||||||||||||||||||||||
| 515 | 2 | $inliner->read_file({ filename => $file }); | |||||||||||||||||||||||||||||||||||||
| 516 | 2 | $html = $inliner->inlinify(); | |||||||||||||||||||||||||||||||||||||
| 517 | 2 | $d->add(Encode::encode_utf8($html)); | |||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||
| 519 | 1 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||
| 522 | sub bench_datetime { | ||||||||||||||||||||||||||||||||||||||
| 523 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_datetime: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my @tz = map {DateTime::TimeZone->new( name => $_ )} qw(UTC Europe/London America/New_York); | |||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $str; | |||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||
| 528 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $dt = DateTime->now(); | |||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $dt1 = DateTime->from_epoch( | |||||||||||||||||||||||||||||||||||||
| 531 | epoch => 946684800 + rand(100000000), | ||||||||||||||||||||||||||||||||||||||
| 532 | ); | ||||||||||||||||||||||||||||||||||||||
| 533 | 0 | my $dt2 = DateTime->from_epoch( | |||||||||||||||||||||||||||||||||||||
| 534 | epoch => 946684800 + rand(100000000), | ||||||||||||||||||||||||||||||||||||||
| 535 | ); | ||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $str = $dt2->strftime('%FT%T')."\n"; | |||||||||||||||||||||||||||||||||||||
| 537 | 0 | $d->add($str); | |||||||||||||||||||||||||||||||||||||
| 538 | 0 | eval {$dt2->set_time_zone($tz[int(rand(3))])}; | |||||||||||||||||||||||||||||||||||||
| 539 | 0 | my $dur = $dt2->subtract_datetime($dt1); | |||||||||||||||||||||||||||||||||||||
| 540 | 0 | eval {$dt2->add_duration($dur)}; | |||||||||||||||||||||||||||||||||||||
| 541 | 0 | eval {$dt2->subtract(days => int(rand(1000)+1))}; | |||||||||||||||||||||||||||||||||||||
| 542 | 0 | $dt->week; | |||||||||||||||||||||||||||||||||||||
| 543 | 0 | $dt->epoch; | |||||||||||||||||||||||||||||||||||||
| 544 | 0 | $d->add($dt2->strftime('%FT%T')); | |||||||||||||||||||||||||||||||||||||
| 545 | 0 | eval {$dt2->set( year => int(rand(2030)))}; | |||||||||||||||||||||||||||||||||||||
| 546 | 0 | $d->add($dt2->ymd('/')); | |||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||
| 548 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||
| 551 | sub bench_dct { | ||||||||||||||||||||||||||||||||||||||
| 552 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_dct: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 554 | 0 | $d->add(bench_dct_sz(@$_)) foreach [$iter, 32], [$iter, 18], [$iter*8,8]; | |||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||
| 556 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||
| 559 | sub bench_dct_sz { | ||||||||||||||||||||||||||||||||||||||
| 560 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_dct_sz: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 561 | 0 | my $sz = shift; | |||||||||||||||||||||||||||||||||||||
| 562 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 563 | 0 | my @arrays; | |||||||||||||||||||||||||||||||||||||
| 564 | 0 | push @arrays, [map { rand(256) } ( 1..$sz*$sz )] foreach 1..10; | |||||||||||||||||||||||||||||||||||||
| 565 | 0 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 566 | 0 | my $dct = dct2d($arrays[$iter % 10], $sz); | |||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | $d->add($dct->[0]) if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||
| 569 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||
| 572 | sub bench_digest { | ||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_digest: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $str = _read_wiki_files(); | |||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 576 | 0 | my $hex; | |||||||||||||||||||||||||||||||||||||
| 577 | 0 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 578 | 0 | my $d2 = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 579 | 0 | $d2->add($str); | |||||||||||||||||||||||||||||||||||||
| 580 | 0 | $hex = $d2->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 581 | 0 | $d->add($hex); | |||||||||||||||||||||||||||||||||||||
| 582 | 0 | $d2 = Digest->new("SHA-512"); | |||||||||||||||||||||||||||||||||||||
| 583 | 0 | $d2->add($str); | |||||||||||||||||||||||||||||||||||||
| 584 | 0 | $hex = $d2->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 585 | 0 | $d->add($hex); | |||||||||||||||||||||||||||||||||||||
| 586 | 0 | $d2 = Digest->new("SHA-1"); | |||||||||||||||||||||||||||||||||||||
| 587 | 0 | $d2->add($str); | |||||||||||||||||||||||||||||||||||||
| 588 | 0 | $hex = $d2->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 589 | 0 | $d->add($hex); | |||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||
| 591 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||
| 594 | sub bench_encode { | ||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_encode: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my $str = _read_wiki_files('utf8'); | |||||||||||||||||||||||||||||||||||||
| 597 | 0 | my $UTF8 = Encode::find_encoding('UTF-8'); | |||||||||||||||||||||||||||||||||||||
| 598 | 0 | my $UTF16 = Encode::find_encoding('UTF-16'); | |||||||||||||||||||||||||||||||||||||
| 599 | 0 | our $cp1252 = Encode::find_encoding('cp-1252'); | |||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $res = 'PASS'; | |||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $unenc = 0; | |||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||
| 603 | 0 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $bytes = encode_utf8($str); | |||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | $res = 'Fail' unless length($bytes) > length($str); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 606 | 0 | my $cp = decode_utf8($bytes); | |||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | my $enc = rand(1) > 0.25 ? $UTF8 : $UTF16; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $bytes = $enc->encode($cp); | |||||||||||||||||||||||||||||||||||||
| 609 | 0 | $cp = $enc->decode($bytes); | |||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | $res = 'Fail' unless $cp eq $str; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my $str2 = $cp1252->encode($cp); | |||||||||||||||||||||||||||||||||||||
| 612 | 0 | $enc->encode($cp1252->decode($str2)); | |||||||||||||||||||||||||||||||||||||
| 613 | 0 | $unenc = () = $str2 =~ /\?/g; # Non-encodable | |||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||
| 615 | 0 | return "$res $unenc"; | |||||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||
| 618 | sub bench_imager { | ||||||||||||||||||||||||||||||||||||||
| 619 | 1 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_imager: called CC=4 SCAR=26.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 620 | 1 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||
| 622 | 1 | my $data; | |||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | open (my $fh, '<:raw', catfile($datadir,'M31.jpg')) or die $!; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 624 | 0 | read($fh, $data, -s $fh); | |||||||||||||||||||||||||||||||||||||
| 625 | 0 | close($fh); | |||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||
| 627 | 0 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | my $img = Imager->new(data=>$data) or die Imager->errstr(); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $thumb = $img->scale(scalefactor=>.3); | |||||||||||||||||||||||||||||||||||||
| 630 | 0 | my $newimg = $img->scale(scalefactor=>1.15); | |||||||||||||||||||||||||||||||||||||
| 631 | 0 | $newimg->filter(type=>'autolevels'); | |||||||||||||||||||||||||||||||||||||
| 632 | 0 | $newimg->filter(type=>"gaussian", stddev=>0.5); | |||||||||||||||||||||||||||||||||||||
| 633 | 0 | $newimg->paste(left=>40,top=>20,img=>$thumb); | |||||||||||||||||||||||||||||||||||||
| 634 | 0 | $newimg->rubthrough(src=>$thumb,tx=>30, ty=>50); | |||||||||||||||||||||||||||||||||||||
| 635 | 0 | $newimg->compose(src => $thumb, tx => 30, ty => 20, combine => 'color'); | |||||||||||||||||||||||||||||||||||||
| 636 | 0 | $newimg->flip(dir=>"h"); | |||||||||||||||||||||||||||||||||||||
| 637 | 0 | $newimg->flip(dir=>"vh"); | |||||||||||||||||||||||||||||||||||||
| 638 | 0 | $d->add(scalar(Image::PHash->new($newimg)->pHash)); | |||||||||||||||||||||||||||||||||||||
| 639 | 0 | $newimg = $img->crop(left=>50, right=>100, top=>10, bottom=>100); | |||||||||||||||||||||||||||||||||||||
| 640 | 0 | $newimg = $img->crop(left=>50, top=>10, width=>50, height=>90); | |||||||||||||||||||||||||||||||||||||
| 641 | 0 | $newimg = $img->copy(); | |||||||||||||||||||||||||||||||||||||
| 642 | 0 | $newimg->filter(type=>"unsharpmask", stddev=>1, scale=>0.5); | |||||||||||||||||||||||||||||||||||||
| 643 | 0 | $newimg = $img->rotate(degrees=>20); | |||||||||||||||||||||||||||||||||||||
| 644 | 0 | $newimg->filter(type=>"contrast", intensity=>1.4); | |||||||||||||||||||||||||||||||||||||
| 645 | 0 | $newimg = $img->convert(matrix => [[0, 1, 0], [1, 0, 0], [0, 0, 1]]); | |||||||||||||||||||||||||||||||||||||
| 646 | 0 | $newimg = $img->convert(preset=>'grey'); | |||||||||||||||||||||||||||||||||||||
| 647 | 0 | $d->add(scalar(Image::PHash->new($newimg)->pHash)); | |||||||||||||||||||||||||||||||||||||
| 648 | 0 | $img->filter(type=>'mandelbrot'); | |||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||
| 650 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||
| 653 | sub bench_json { | ||||||||||||||||||||||||||||||||||||||
| 654 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_json: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 655 | 0 | my $res = 'PASS'; | |||||||||||||||||||||||||||||||||||||
| 656 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 657 | 0 | my $len = int(rand(40)) + 1; | |||||||||||||||||||||||||||||||||||||
| 658 | 0 | my $obj = rand_hash($len); | |||||||||||||||||||||||||||||||||||||
| 659 | 0 | my $str = encode_json($obj); | |||||||||||||||||||||||||||||||||||||
| 660 | 0 | foreach (1..100) { | |||||||||||||||||||||||||||||||||||||
| 661 | 0 | $obj = decode_json($str); | |||||||||||||||||||||||||||||||||||||
| 662 | 0 | $str = encode_json($obj); | |||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $obj2 = decode_json($str); | |||||||||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | $res = 'FAIL' unless compare_obj($obj, $obj2); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||
| 667 | 0 | return $res; | |||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||
| 670 | sub bench_jwt { | ||||||||||||||||||||||||||||||||||||||
| 671 | 1 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_jwt: called CC=4 SCAR=18.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 672 | 1 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 673 | 1 | my $data = _random_str(5000); | |||||||||||||||||||||||||||||||||||||
| 674 | 1 | my $rsa ='-----BEGIN PRIVATE KEY----- | |||||||||||||||||||||||||||||||||||||
| 675 | MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqPfgaTEWEP3S9w0t | ||||||||||||||||||||||||||||||||||||||
| 676 | gsicURfo+nLW09/0KfOPinhYZ4ouzU+3xC4pSlEp8Ut9FgL0AgqNslNaK34Kq+NZ | ||||||||||||||||||||||||||||||||||||||
| 677 | jO9DAQIDAQABAkAgkuLEHLaqkWhLgNKagSajeobLS3rPT0Agm0f7k55FXVt743hw | ||||||||||||||||||||||||||||||||||||||
| 678 | Ngkp98bMNrzy9AQ1mJGbQZGrpr4c8ZAx3aRNAiEAoxK/MgGeeLui385KJ7ZOYktj | ||||||||||||||||||||||||||||||||||||||
| 679 | hLBNAB69fKwTZFsUNh0CIQEJQRpFCcydunv2bENcN/oBTRw39E8GNv2pIcNxZkcb | ||||||||||||||||||||||||||||||||||||||
| 680 | NQIgbYSzn3Py6AasNj6nEtCfB+i1p3F35TK/87DlPSrmAgkCIQDJLhFoj1gbwRbH | ||||||||||||||||||||||||||||||||||||||
| 681 | /bDRPrtlRUDDx44wHoEhSDRdy77eiQIgE6z/k6I+ChN1LLttwX0galITxmAYrOBh | ||||||||||||||||||||||||||||||||||||||
| 682 | BVl433tgTTQ= | ||||||||||||||||||||||||||||||||||||||
| 683 | -----END PRIVATE KEY-----'; | ||||||||||||||||||||||||||||||||||||||
| 684 | 1 | my $key = '-----BEGIN PRIVATE KEY----- | |||||||||||||||||||||||||||||||||||||
| 685 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgYirTZSx+5O8Y6tlG | ||||||||||||||||||||||||||||||||||||||
| 686 | cka6W6btJiocdrdolfcukSoTEk+hRANCAAQkvPNu7Pa1GcsWU4v7ptNfqCJVq8Cx | ||||||||||||||||||||||||||||||||||||||
| 687 | zo0MUVPQgwJ3aJtNM1QMOQUayCrRwfklg+D/rFSUwEUqtZh7fJDiFqz3 | ||||||||||||||||||||||||||||||||||||||
| 688 | -----END PRIVATE KEY-----'; | ||||||||||||||||||||||||||||||||||||||
| 689 | 1 | foreach (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 690 | 1 | my $extra = _random_str(100); | |||||||||||||||||||||||||||||||||||||
| 691 | 1 | my $data_in = $data.$extra; | |||||||||||||||||||||||||||||||||||||
| 692 | 1 | my $token = encode_jwt( | |||||||||||||||||||||||||||||||||||||
| 693 | payload => $data_in, | ||||||||||||||||||||||||||||||||||||||
| 694 | alg => 'ES256', | ||||||||||||||||||||||||||||||||||||||
| 695 | key => \$key, | ||||||||||||||||||||||||||||||||||||||
| 696 | ); | ||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||
| 698 | 0 | my $data_out = _decode_jwt2(token=>$token, key=>\$key); | |||||||||||||||||||||||||||||||||||||
| 699 | 0 | ▶ | $d->add($token) if $data_in eq $data_out.$extra; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||
| 701 | 0 | $token = encode_jwt( | |||||||||||||||||||||||||||||||||||||
| 702 | payload => $data_in, | ||||||||||||||||||||||||||||||||||||||
| 703 | alg => 'RS256', | ||||||||||||||||||||||||||||||||||||||
| 704 | key => \$rsa, | ||||||||||||||||||||||||||||||||||||||
| 705 | ); | ||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||
| 707 | 0 | $data_out = _decode_jwt2(token=>$token, key=>\$rsa); | |||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | $d->add($token) if $data_in eq $data_out.$extra; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||
| 710 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||
| 713 | sub bench_formattext { | ||||||||||||||||||||||||||||||||||||||
| 714 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_formattext: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 715 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 716 | 0 | my $file; | |||||||||||||||||||||||||||||||||||||
| 717 | 0 | for (0..$iter-1) { | |||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $i = $_ % 2; | |||||||||||||||||||||||||||||||||||||
| 719 | 0 | $file = catfile($datadir, "wiki$i.html"); | |||||||||||||||||||||||||||||||||||||
| 720 | 0 | my $tree = HTML::TreeBuilder->new->parse_file($file); | |||||||||||||||||||||||||||||||||||||
| 721 | 0 | my $formatter = HTML::FormatText->new(); | |||||||||||||||||||||||||||||||||||||
| 722 | 0 | my $text = $formatter->format($tree); | |||||||||||||||||||||||||||||||||||||
| 723 | 0 | $formatter = HTML::FormatText->new(leftmargin => 0, rightmargin => 30); | |||||||||||||||||||||||||||||||||||||
| 724 | 0 | $d->add(Encode::encode_utf8($formatter->format($tree))); | |||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||
| 726 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||
| 729 | sub bench_matrixreal { | ||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_matrixreal: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 731 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 732 | 0 | my $smatrix = Math::MatrixReal->new_random(13); | |||||||||||||||||||||||||||||||||||||
| 733 | 0 | my $matrix = Math::MatrixReal->new_random(20); | |||||||||||||||||||||||||||||||||||||
| 734 | 0 | my $bmatrix = Math::MatrixReal->new_random(72); | |||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||
| 736 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 737 | 0 | my $r = rand(10); | |||||||||||||||||||||||||||||||||||||
| 738 | 0 | my $m1 = $r*$bmatrix; | |||||||||||||||||||||||||||||||||||||
| 739 | 0 | my $m2 = $bmatrix*$r; | |||||||||||||||||||||||||||||||||||||
| 740 | 0 | my $m3 = $bmatrix->multiply_scalar($bmatrix,$r); | |||||||||||||||||||||||||||||||||||||
| 741 | # Should be zero | ||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | $d->add($m1->element(1, 1) + $m2->element(1, 1) - 2 * $bmatrix->element(1, 1)) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 743 | if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||
| 745 | 0 | my $m = $matrix->det; | |||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | $d->add($m) if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 747 | 0 | $m =$matrix->decompose_LR->det_LR; | |||||||||||||||||||||||||||||||||||||
| 748 | 0 | ▶ | $d->add($m) if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $m1 = $matrix ** 2; | |||||||||||||||||||||||||||||||||||||
| 750 | 0 | $m2 = $matrix * $matrix; | |||||||||||||||||||||||||||||||||||||
| 751 | #should be zero | ||||||||||||||||||||||||||||||||||||||
| 752 | 0 | ▶ | $d->add($m1->element(1, 1) - $m2->element(1, 1)) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 753 | if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||||
| 754 | 0 | $m1 = $smatrix->inverse(); | |||||||||||||||||||||||||||||||||||||
| 755 | 0 | $m2 = $smatrix ** -1; | |||||||||||||||||||||||||||||||||||||
| 756 | 0 | $m3 = $smatrix->decompose_LR->invert_LR; | |||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | $d->add($m1->element(1, 1), $m2->element(1, 1), $m3->element(1, 1)) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 758 | if $_ % 10 == 1; | ||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||
| 761 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||
| 764 | sub bench_moose { | ||||||||||||||||||||||||||||||||||||||
| 765 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_moose: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 766 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||
| 768 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 769 | 0 | my $p = rand(1000); | |||||||||||||||||||||||||||||||||||||
| 770 | 0 | my $root = Benchmark::DKbench::MooseTree->new(node => 'root'); | |||||||||||||||||||||||||||||||||||||
| 771 | 0 | $root->price($p); | |||||||||||||||||||||||||||||||||||||
| 772 | 0 | $root->node; | |||||||||||||||||||||||||||||||||||||
| 773 | 0 | $root->cost; | |||||||||||||||||||||||||||||||||||||
| 774 | 0 | my $lchild = $root->left; | |||||||||||||||||||||||||||||||||||||
| 775 | 0 | $lchild->node('child'); | |||||||||||||||||||||||||||||||||||||
| 776 | 0 | $lchild->price($p); | |||||||||||||||||||||||||||||||||||||
| 777 | 0 | $lchild->tax; | |||||||||||||||||||||||||||||||||||||
| 778 | 0 | my $child = $root->right; | |||||||||||||||||||||||||||||||||||||
| 779 | 0 | $child->cost; | |||||||||||||||||||||||||||||||||||||
| 780 | 0 | my $grandchild = $child->left; | |||||||||||||||||||||||||||||||||||||
| 781 | 0 | $grandchild->node('grandchild'); | |||||||||||||||||||||||||||||||||||||
| 782 | 0 | $grandchild->has_parent; | |||||||||||||||||||||||||||||||||||||
| 783 | 0 | $grandchild->parent; | |||||||||||||||||||||||||||||||||||||
| 784 | 0 | $grandchild->price($p); | |||||||||||||||||||||||||||||||||||||
| 785 | 0 | $grandchild->cost; | |||||||||||||||||||||||||||||||||||||
| 786 | 0 | my $ggchild = $grandchild->right; | |||||||||||||||||||||||||||||||||||||
| 787 | 0 | $ggchild->cost; | |||||||||||||||||||||||||||||||||||||
| 788 | 0 | $cnt += 5; | |||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||
| 790 | 0 | return md5_hex("$cnt objects"); | |||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||
| 793 | sub bench_moose_prv { | ||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_moose_prv: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 795 | 0 | my $tdir = catfile($datadir, 't'); | |||||||||||||||||||||||||||||||||||||
| 796 | 0 | my $result; | |||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if ($iter < 1) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 798 | 0 | $tdir = catfile($tdir, 'recipes'); | |||||||||||||||||||||||||||||||||||||
| 799 | 0 | $result = `prove -rQ $tdir`; | |||||||||||||||||||||||||||||||||||||
| 800 | } else { | ||||||||||||||||||||||||||||||||||||||
| 801 | 0 | $result = `prove -rQ $tdir` for (1..$iter); | |||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||
| 803 | 0 | ▶ | if ($result =~ /Result: (\w*)/) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 804 | 0 | return $1; | |||||||||||||||||||||||||||||||||||||
| 805 | } else { | ||||||||||||||||||||||||||||||||||||||
| 806 | 0 | return '?'; | |||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||
| 810 | sub bench_primes_m { | ||||||||||||||||||||||||||||||||||||||
| 811 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_primes_m: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 812 | 0 | return bench_primes($iter, 7_500_000); | |||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||
| 815 | sub bench_primes { | ||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_primes: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 817 | 0 | my $max = shift; | |||||||||||||||||||||||||||||||||||||
| 818 | 0 | my @primes; | |||||||||||||||||||||||||||||||||||||
| 819 | 0 | @primes = _get_primes($max) for (1..$iter); | |||||||||||||||||||||||||||||||||||||
| 820 | 0 | return md5_hex(scalar(@primes)." primes up to $max"); | |||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||
| 823 | sub bench_regex_asc { | ||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_regex_asc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 825 | 0 | return bench_regex_subst($iter, ''); | |||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||
| 828 | sub bench_regex_utf8 { | ||||||||||||||||||||||||||||||||||||||
| 829 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_regex_utf8: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 830 | 0 | return bench_regex_subst($iter, 'utf8'); | |||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||
| 833 | sub bench_regex_subst { | ||||||||||||||||||||||||||||||||||||||
| 834 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_regex_subst: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 835 | 0 | my $enc = shift; | |||||||||||||||||||||||||||||||||||||
| 836 | 0 | my $str = _read_wiki_files($enc); | |||||||||||||||||||||||||||||||||||||
| 837 | 0 | my $match = bench_regex($str, $iter); | |||||||||||||||||||||||||||||||||||||
| 838 | 0 | my $repl = bench_subst($str, $iter); | |||||||||||||||||||||||||||||||||||||
| 839 | 0 | return md5_hex($match, $repl); | |||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||
| 842 | sub bench_regex { | ||||||||||||||||||||||||||||||||||||||
| 843 | 0 | ▶ | my $str = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_regex: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 844 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||
| 845 | 0 | my $count; | |||||||||||||||||||||||||||||||||||||
| 846 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 847 | 0 | $count = 0; | |||||||||||||||||||||||||||||||||||||
| 848 | 0 | $count += () = $str =~ /\b[A-Z][a-z]+/g; | |||||||||||||||||||||||||||||||||||||
| 849 | 0 | $count += () = $str =~ /([\w\.+-]+)@[\w\.-]+\.([\w\.-]+)/g; | |||||||||||||||||||||||||||||||||||||
| 850 | 0 | $count += () = $str =~ m![\w]+://[^/\s?#]+[^\s?#]+(?:\?[^\s#]*)?(?:#[^\s]*)?!g; | |||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||
| 852 | 0 | return "$count Matched"; | |||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||
| 855 | sub bench_subst { | ||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | my $str = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_subst: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||
| 858 | 0 | my $count; | |||||||||||||||||||||||||||||||||||||
| 859 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 860 | 0 | my $copy = $str; | |||||||||||||||||||||||||||||||||||||
| 861 | 0 | $count = 0; | |||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | while (my $s = $copy =~ s#<([^>]+)>([^>]*?)</\1>#$2#g) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 863 | 0 | $count += $s; | |||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||
| 865 | 0 | $copy = substr($copy, int(rand(100))+1) for 1..10; | |||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||
| 867 | 0 | return "$count Replaced"; | |||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||
| 870 | sub bench_timepiece { | ||||||||||||||||||||||||||||||||||||||
| 871 | 0 | ▶ | my $iter = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
bench_timepiece: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 872 | 0 | my $t = Time::Piece::localtime(1692119499); | |||||||||||||||||||||||||||||||||||||
| 873 | 0 | my $d = Digest->new("MD5"); | |||||||||||||||||||||||||||||||||||||
| 874 | 0 | my $day = 3600*24; | |||||||||||||||||||||||||||||||||||||
| 875 | 0 | local $ENV{TZ} = 'UTC'; | |||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||
| 877 | 0 | for (1..$iter) { | |||||||||||||||||||||||||||||||||||||
| 878 | 0 | $t += int(rand(1000)-500)*$day; | |||||||||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | $t += 100000*$day if $t->year < 1970; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 880 | 0 | my $str = $t->strftime("%a, %d %b %Y %H:%M:%S"); | |||||||||||||||||||||||||||||||||||||
| 881 | 0 | $t = Time::Piece->strptime($str, "%a, %d %b %Y %H:%M:%S"); | |||||||||||||||||||||||||||||||||||||
| 882 | 0 | my $jd = $t->julian_day; | |||||||||||||||||||||||||||||||||||||
| 883 | 0 | $d->add($str,$jd); | |||||||||||||||||||||||||||||||||||||
| 884 | } | ||||||||||||||||||||||||||||||||||||||
| 885 | 0 | return $d->hexdigest; | |||||||||||||||||||||||||||||||||||||
| 886 | } | ||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||
| 888 | sub total_stats { | ||||||||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | my ($opt, $stats) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
total_stats: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 890 | 0 | my $benchmarks = benchmark_list(); | |||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | my $display = $opt->{time} ? 'times' : 'scores'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | my $title = $opt->{time} ? 'Time (sec)' : 'Score'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 893 | 0 | print "Aggregates:\n".pad_to("Benchmark",24).pad_to("Avg $title").pad_to("Min $title").pad_to("Max $title"); | |||||||||||||||||||||||||||||||||||||
| 894 | 0 | ▶ | print pad_to("Pass %") unless $opt->{time}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 895 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||
| 896 | 0 | foreach my $bench (sort keys %$benchmarks) { | |||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | next unless $stats->{$bench}->{$display}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 898 | 0 | my $str = calc_stats($opt, $stats->{$bench}->{$display}); | |||||||||||||||||||||||||||||||||||||
| 899 | 0 | print pad_to("$bench:",24).$str; | |||||||||||||||||||||||||||||||||||||
| 900 | print pad_to( | ||||||||||||||||||||||||||||||||||||||
| 901 | sprintf("%d", 100 * ($opt->{iter}-($stats->{$bench}->{fail} || 0)) / $opt->{iter})) | ||||||||||||||||||||||||||||||||||||||
| 902 | 0 | ▶ | unless $opt->{time}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$stats->{$bench}{'fail'} || 0
MC/DC0%0/1
$stats->{$bench}{'fail'} || 0
$stats->{$bench}{'fail'}
Truth table0%0/2
A
A= $stats->{$bench}{'fail'}
| |||||||||||||||||||||||||||||||||||||||
| 903 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||
| 905 | 0 | my $str = calc_stats($opt, $stats->{total}->{$display}); | |||||||||||||||||||||||||||||||||||||
| 906 | 0 | print pad_to("Overall Avg $title:", 24)."$str\n"; | |||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||
| 909 | sub calc_stats { | ||||||||||||||||||||||||||||||||||||||
| 910 | 0 | ▶ | my $opt = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
calc_stats: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 911 | 0 | my $arr = shift; | |||||||||||||||||||||||||||||||||||||
| 912 | 0 | my $pad = shift; | |||||||||||||||||||||||||||||||||||||
| 913 | 0 | my ($min, $max, $avg) = min_max_avg($arr); | |||||||||||||||||||||||||||||||||||||
| 914 | 0 | return $avg, join '', map {pad_to(sprintf($opt->{f}, $_), $pad)} ($avg,$min,$max); | |||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||
| 917 | sub min_max_avg { | ||||||||||||||||||||||||||||||||||||||
| 918 | 4 | ▶ | my $arr = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
min_max_avg: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 919 | 4 | ▶ | return (0, 0, 0) unless @$arr; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 920 | 3 | return min(@$arr), max(@$arr), sum(@$arr)/scalar(@$arr); | |||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||
| 923 | sub avg_stdev { | ||||||||||||||||||||||||||||||||||||||
| 924 | 4 | ▶ | my $arr = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
avg_stdev: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 925 | 4 | ▶ | return (0, 0) unless @$arr; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 926 | 3 | my $sum = sum(@$arr); | |||||||||||||||||||||||||||||||||||||
| 927 | 3 | my $avg = $sum/scalar(@$arr); | |||||||||||||||||||||||||||||||||||||
| 928 | 3 | my @sq; | |||||||||||||||||||||||||||||||||||||
| 929 | 3 | push @sq, ($avg - $_)**2 for (@$arr); | |||||||||||||||||||||||||||||||||||||
| 930 | 3 | my $dev = min_max_avg(\@sq); | |||||||||||||||||||||||||||||||||||||
| 931 | 3 | return $avg, sqrt($dev); | |||||||||||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||
| 934 | # $single = single tail of dist curve outlier, 1 for over (right), -1 for under (left) | ||||||||||||||||||||||||||||||||||||||
| 935 | sub drop_outliers { | ||||||||||||||||||||||||||||||||||||||
| 936 | 3 | ▶ | my $arr = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
drop_outliers: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 937 | 3 | my $single = shift; | |||||||||||||||||||||||||||||||||||||
| 938 | 3 | my ($avg, $stdev) = avg_stdev($arr); | |||||||||||||||||||||||||||||||||||||
| 939 | 3 | my @newarr; | |||||||||||||||||||||||||||||||||||||
| 940 | 3 | foreach (@$arr) { | |||||||||||||||||||||||||||||||||||||
| 941 | 39 | ▶ | if ($single) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 942 | 26 | ▶ | push @newarr, $_ unless $single*($_ - $avg) > 2*$stdev; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 943 | } else { | ||||||||||||||||||||||||||||||||||||||
| 944 | 13 | ▶ | push @newarr, $_ unless abs($avg - $_) > 2*$stdev; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||
| 947 | 3 | return @newarr; | |||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||
| 950 | sub pad_to { | ||||||||||||||||||||||||||||||||||||||
| 951 | 8 | ▶ | my $str = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
pad_to: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 952 | 8 | ▶ | my $len = shift || 20; | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 20
MC/DC0%0/1
shift() || 20
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 953 | 8 | return $str." "x($len-length($str)); | |||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||
| 956 | sub _read_wiki_files { | ||||||||||||||||||||||||||||||||||||||
| 957 | 0 | ▶ | my $enc = shift || ''; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_wiki_files: not called CC=4 SCAR=30.0
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 958 | 0 | my $str = ""; | |||||||||||||||||||||||||||||||||||||
| 959 | 0 | for (0..2) { | |||||||||||||||||||||||||||||||||||||
| 960 | 0 | ▶ | open my $fh, "<:$enc", catfile($datadir,"wiki$_.html") or die $!; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 961 | 0 | $str .= do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||
| 963 | 0 | return $str; | |||||||||||||||||||||||||||||||||||||
| 964 | } | ||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||
| 966 | sub _random_str { | ||||||||||||||||||||||||||||||||||||||
| 967 | 3 | ▶ | my $length = shift || 1; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_random_str: called CC=3 SCAR=11.0
Condition100%2/2
shift() || 1
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||
| 968 | 3 | my $str = ""; | |||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||
| 970 | 3 | $str .= chr(int(rand(95))+32) for 1..$length; | |||||||||||||||||||||||||||||||||||||
| 971 | 3 | return $str; | |||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||
| 974 | sub _random_uchar { | ||||||||||||||||||||||||||||||||||||||
| 975 | 0 | ▶ | my $chr = int(rand(800))+32; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_random_uchar: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | $chr += 128 if $chr > 127; # Skip Latin 1 supplement | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 977 | 0 | ▶ | $chr += 288 if $chr > 591; # Skip pre-Greek blocks | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 978 | 0 | return chr($chr); | |||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||
| 981 | sub compare_obj { | ||||||||||||||||||||||||||||||||||||||
| 982 | 4 | ▶ | my ($obj1, $obj2) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_obj: called CC=4 SCAR=15.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 983 | 4 | my $t1 = ref($obj1); | |||||||||||||||||||||||||||||||||||||
| 984 | 4 | my $t2 = ref($obj2); | |||||||||||||||||||||||||||||||||||||
| 985 | 4 | ▶ | return 0 if $t1 ne $t2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 986 | 3 | ▶ | return $obj1 eq $obj2 unless $t1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 987 | 0 | ▶ | return $t1 eq 'ARRAY' ? compare_arr($obj1, $obj2) : compare_hash($obj1, $obj2); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 988 | } | ||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||
| 990 | sub compare_arr { | ||||||||||||||||||||||||||||||||||||||
| 991 | 2 | ▶ | my ($arr1, $arr2) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_arr: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 992 | 2 | my $sz = scalar @$arr1; | |||||||||||||||||||||||||||||||||||||
| 993 | 2 | ▶ | return 0 if $sz != scalar @$arr2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 994 | 1 | for (0..$sz-1) { | |||||||||||||||||||||||||||||||||||||
| 995 | 2 | ▶ | return 0 unless compare_obj($arr1->[$_], $arr2->[$_]); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 996 | } | ||||||||||||||||||||||||||||||||||||||
| 997 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 998 | } | ||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||
| 1000 | sub compare_hash { | ||||||||||||||||||||||||||||||||||||||
| 1001 | 2 | ▶ | my ($h1, $h2) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_hash: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 1002 | 2 | ▶ | return 0 if scalar keys %$h1 != scalar keys %$h2; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1003 | 1 | for (keys %$h1) { | |||||||||||||||||||||||||||||||||||||
| 1004 | 1 | ▶ | return 0 unless compare_obj($h1->{$_}, $h2->{$_}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1005 | } | ||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||
| 1007 | } | ||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||
| 1009 | sub rand_arr { | ||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | my $sz = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
rand_arr: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | my @arr; | |||||||||||||||||||||||||||||||||||||
| 1012 | 0 | for (1..$sz) { | |||||||||||||||||||||||||||||||||||||
| 1013 | 0 | my $len = int(rand(10)) + 1; | |||||||||||||||||||||||||||||||||||||
| 1014 | 0 | ▶ | my $item = rand(1) < 0.9 ? _random_uchar()x($len*5) : rand(1) < 0.5 ? rand_arr($len) : rand_hash($len); | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | push @arr, $item; | |||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | return \@arr; | |||||||||||||||||||||||||||||||||||||
| 1018 | } | ||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||
| 1020 | sub rand_hash { | ||||||||||||||||||||||||||||||||||||||
| 1021 | 0 | ▶ | my $sz = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
rand_hash: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | my %hash; | |||||||||||||||||||||||||||||||||||||
| 1023 | 0 | for (1..$sz) { | |||||||||||||||||||||||||||||||||||||
| 1024 | 0 | my $len = int(rand(10)) + 1; | |||||||||||||||||||||||||||||||||||||
| 1025 | 0 | ▶ | my $item = rand(1) < 0.9 ? _random_uchar()x($len*5) : rand(1) < 0.5 ? rand_arr($len) : rand_hash($len); | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 1026 | 0 | $hash{_random_uchar()x($len*4)} = $item; | |||||||||||||||||||||||||||||||||||||
| 1027 | } | ||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | return \%hash; | |||||||||||||||||||||||||||||||||||||
| 1029 | } | ||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||
| 1031 | # modified from https://github.com/famzah/langs-performance/blob/master/primes.pl | ||||||||||||||||||||||||||||||||||||||
| 1032 | sub _get_primes { | ||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | my $n = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_primes: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | my @s = (); | |||||||||||||||||||||||||||||||||||||
| 1035 | 0 | ▶ | for (my $i = 3; $i < $n + 1; $i += 2) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | push(@s, $i); | |||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | my $mroot = $n**0.5; | |||||||||||||||||||||||||||||||||||||
| 1039 | 0 | my $half = scalar @s; | |||||||||||||||||||||||||||||||||||||
| 1040 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||
| 1041 | 0 | my $m = 3; | |||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | while ($m <= $mroot) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | ▶ | if ($s[$i]) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | ▶ | for (my $j = int(($m * $m - 3) / 2); $j < $half; $j += $m) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | $s[$j] = 0; | |||||||||||||||||||||||||||||||||||||
| 1046 | } | ||||||||||||||||||||||||||||||||||||||
| 1047 | } | ||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||
| 1049 | 0 | $m = 2 * $i + 3; | |||||||||||||||||||||||||||||||||||||
| 1050 | } | ||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | return 2, grep($_, @s); | |||||||||||||||||||||||||||||||||||||
| 1053 | } | ||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||
| 1055 | # Fix for Crypt::JWT that was submitted as a patch. Will remove if it is merged. | ||||||||||||||||||||||||||||||||||||||
| 1056 | sub _decode_jwt2 { | ||||||||||||||||||||||||||||||||||||||
| 1057 | 1 | ▶ | my %args = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_decode_jwt2: called CC=4 SCAR=19.4
| |||||||||||||||||||||||||||||||||||||||
| 1058 | 1 | my ($header, $payload); | |||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||
| 1060 | 1 | ▶ | if ($args{token} =~ | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1061 | /^([a-zA-Z0-9_-]+)=*\.([a-zA-Z0-9_-]*)=*\.([a-zA-Z0-9_-]*)=*(?:\.([a-zA-Z0-9_-]+)=*\.([a-zA-Z0-9_-]+)=*)?$/ | ||||||||||||||||||||||||||||||||||||||
| 1062 | ) { | ||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | ▶ | if (length($5)) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1064 | # JWE token (5 segments) | ||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | ($header, $payload) = | |||||||||||||||||||||||||||||||||||||
| 1066 | Crypt::JWT::_decode_jwe($1, $2, $3, $4, $5, undef, {}, {}, | ||||||||||||||||||||||||||||||||||||||
| 1067 | %args); | ||||||||||||||||||||||||||||||||||||||
| 1068 | } else { | ||||||||||||||||||||||||||||||||||||||
| 1069 | # JWS token (3 segments) | ||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | ($header, $payload) = | |||||||||||||||||||||||||||||||||||||
| 1071 | Crypt::JWT::_decode_jws($1, $2, $3, {}, %args); | ||||||||||||||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||||||||||||
| 1073 | } | ||||||||||||||||||||||||||||||||||||||
| 1074 | 1 | ▶ | return ($header, $payload) if $args{decode_header}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1075 | 0 | return $payload; | |||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||||||
| 1078 | # Helper package for Moose benchmark | ||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||
| 1080 | { | ||||||||||||||||||||||||||||||||||||||
| 1081 | package Benchmark::DKbench::MooseTree; | ||||||||||||||||||||||||||||||||||||||
| 1082 | |||||||||||||||||||||||||||||||||||||||
| 1083 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 1084 | |||||||||||||||||||||||||||||||||||||||
| 1085 | 3 | has 'price' => (is => 'rw', default => 10); | |||||||||||||||||||||||||||||||||||||
| 1086 | 3 | has 'tax' => (is => 'rw', lazy_build => 1); | |||||||||||||||||||||||||||||||||||||
| 1087 | 3 | has 'node' => (is => 'rw', isa => 'Any'); | |||||||||||||||||||||||||||||||||||||
| 1088 | 3 | has 'parent' => ( | |||||||||||||||||||||||||||||||||||||
| 1089 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||
| 1090 | isa => 'Benchmark::DKbench::MooseTree', | ||||||||||||||||||||||||||||||||||||||
| 1091 | predicate => 'has_parent', | ||||||||||||||||||||||||||||||||||||||
| 1092 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||
| 1093 | ); | ||||||||||||||||||||||||||||||||||||||
| 1094 | 3 | has 'left' => ( | |||||||||||||||||||||||||||||||||||||
| 1095 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||
| 1096 | isa => 'Benchmark::DKbench::MooseTree', | ||||||||||||||||||||||||||||||||||||||
| 1097 | predicate => 'has_left', | ||||||||||||||||||||||||||||||||||||||
| 1098 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 1099 | builder => '_build_child_tree', | ||||||||||||||||||||||||||||||||||||||
| 1100 | ); | ||||||||||||||||||||||||||||||||||||||
| 1101 | 3 | has 'right' => ( | |||||||||||||||||||||||||||||||||||||
| 1102 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||
| 1103 | isa => 'Benchmark::DKbench::MooseTree', | ||||||||||||||||||||||||||||||||||||||
| 1104 | predicate => 'has_right', | ||||||||||||||||||||||||||||||||||||||
| 1105 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 1106 | builder => '_build_child_tree', | ||||||||||||||||||||||||||||||||||||||
| 1107 | ); | ||||||||||||||||||||||||||||||||||||||
| 1108 | before 'right', 'left' => sub { | ||||||||||||||||||||||||||||||||||||||
| 1109 | 0 | ▶ | my ($self, $tree) = @_; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | ▶ | $tree->parent($self) if defined $tree; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 1111 | 3 | }; | |||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||
| 1113 | sub _build_tax { | ||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_tax: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | $self->price * 0.2; | |||||||||||||||||||||||||||||||||||||
| 1116 | } | ||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||
| 1118 | sub _build_child_tree { | ||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_child_tree: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | return Benchmark::DKbench::MooseTree->new( parent => $self ); | |||||||||||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||
| 1123 | sub cost { | ||||||||||||||||||||||||||||||||||||||
| 1124 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
cost: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | $self->price + $self->tax; | |||||||||||||||||||||||||||||||||||||
| 1126 | } | ||||||||||||||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||
| 1129 | 3 | 1; | |||||||||||||||||||||||||||||||||||||