line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PerlBench::Stats; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3540
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
9
|
use base 'Exporter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
457
|
|
6
|
|
|
|
|
|
|
our @EXPORT_OK = qw(calc_stats); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub calc_stats { |
9
|
6
|
|
|
6
|
0
|
2312
|
my($samples, $hash) = @_; |
10
|
6
|
|
50
|
|
|
45
|
$hash ||= {}; |
11
|
6
|
|
|
|
|
27
|
my @t = sort {$a <=> $b} @$samples; |
|
8
|
|
|
|
|
28
|
|
12
|
6
|
|
|
|
|
16
|
my $n = @t; |
13
|
6
|
100
|
|
|
|
25
|
return undef unless $n; |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
|
|
12
|
my $sum = 0; |
16
|
5
|
|
|
|
|
11
|
my $sum2 = 0; |
17
|
5
|
|
|
|
|
17
|
for (@t) { |
18
|
12
|
|
|
|
|
37
|
$sum += $_; |
19
|
12
|
|
|
|
|
30
|
$sum2 += $_ * $_; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
20
|
$hash->{avg} = $sum / $n; |
23
|
5
|
|
|
|
|
20
|
$hash->{stddev} = sqrt(($sum2 - ($sum * $sum)/$n) / $n); |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
14
|
$hash->{min} = $t[0]; |
26
|
5
|
100
|
|
|
|
26
|
$hash->{med} = ($n % 2) ? $t[$n/2] : (($t[$n/2-1] + $t[$n/2])/2); |
27
|
5
|
|
|
|
|
15
|
$hash->{max} = $t[-1]; |
28
|
5
|
|
|
|
|
13
|
$hash->{n} = $n; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
20
|
return $hash; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |