| 1 | package PerlBench::Stats; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 2 | ▶ | use base 'Exporter'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 2 | our @EXPORT_OK = qw(calc_stats); | |||||||||||
| 7 | |||||||||||||
| 8 | 6 | ▶ | sub calc_stats { | ||||||||||
|
Subroutine
calc_stats: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||
| 9 | 6 | my($samples, $hash) = @_; | |||||||||||
| 10 | 6 | ▶ | $hash ||= {}; | ||||||||||
|
Condition50%1/2
$hash ||= {}
MC/DC0%0/1
$hash ||= {}
$hash
Truth table50%1/2
A
A= $hash
| |||||||||||||
| 11 | 6 | my @t = sort {$a <=> $b} @$samples; | |||||||||||
| 12 | 6 | my $n = @t; | |||||||||||
| 13 | 6 | ▶ | return undef unless $n; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | |||||||||||||
| 15 | 5 | my $sum = 0; | |||||||||||
| 16 | 5 | my $sum2 = 0; | |||||||||||
| 17 | 5 | for (@t) { | |||||||||||
| 18 | 12 | $sum += $_; | |||||||||||
| 19 | 12 | $sum2 += $_ * $_; | |||||||||||
| 20 | } | ||||||||||||
| 21 | |||||||||||||
| 22 | 5 | $hash->{avg} = $sum / $n; | |||||||||||
| 23 | 5 | $hash->{stddev} = sqrt(($sum2 - ($sum * $sum)/$n) / $n); | |||||||||||
| 24 | |||||||||||||
| 25 | 5 | $hash->{min} = $t[0]; | |||||||||||
| 26 | 5 | ▶ | $hash->{med} = ($n % 2) ? $t[$n/2] : (($t[$n/2-1] + $t[$n/2])/2); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 5 | $hash->{max} = $t[-1]; | |||||||||||
| 28 | 5 | $hash->{n} = $n; | |||||||||||
| 29 | |||||||||||||
| 30 | 5 | return $hash; | |||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 2 | 1; | |||||||||||