line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
1
|
|
|
1
|
|
795
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
7
|
1
|
|
|
1
|
|
6
|
use Time::HiRes qw(gettimeofday tv_interval); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
347
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
101
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fix::Bind'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has output => (is => 'ro', required => 1); |
13
|
|
|
|
|
|
|
has stats => (is => 'lazy'); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
+{}; |
16
|
|
|
|
|
|
|
} |
17
|
10
|
|
|
10
|
|
84
|
|
18
|
|
|
|
|
|
|
my ($self, $data, $code, $name) = @_; |
19
|
|
|
|
|
|
|
$name = '<undef>' unless defined $name; |
20
|
|
|
|
|
|
|
my $t0 = [gettimeofday]; |
21
|
|
|
|
|
|
|
$data = $code->($data); |
22
|
|
|
|
|
|
|
my $elapsed = tv_interval($t0); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$self->stats->{$name}->{count} += 1; |
25
|
|
|
|
|
|
|
$self->stats->{$name}->{elapsed} += $elapsed; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$data; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my ($self) = @_; |
31
|
|
|
|
|
|
|
local (*OUT); |
32
|
|
|
|
|
|
|
open(OUT, '>', $self->output) || return undef; |
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
10
|
|
1233
|
printf OUT "%-8.8s\t%-40.40s\t%-8.8s\t%-8.8s\n", 'elapsed', 'command', |
35
|
10
|
|
|
|
|
23
|
'calls', 'sec/command'; |
36
|
10
|
50
|
|
|
|
328
|
printf OUT "-" x 100 . "\n"; |
37
|
|
|
|
|
|
|
|
38
|
10
|
|
|
|
|
107
|
for my $key ( |
39
|
|
|
|
|
|
|
sort {$self->stats->{$b}->{elapsed} cmp $self->stats->{$a}->{elapsed}} |
40
|
10
|
|
|
|
|
32
|
keys %{$self->stats} |
41
|
|
|
|
|
|
|
) |
42
|
10
|
|
|
|
|
18
|
{ |
43
|
2
|
|
|
|
|
46
|
my $speed |
44
|
10
|
|
|
|
|
202
|
= $self->stats->{$key}->{elapsed} / $self->stats->{$key}->{count}; |
45
|
|
|
|
|
|
|
printf OUT "%f\t%-40.40s\t%d times\t%f secs/command\n", |
46
|
|
|
|
|
|
|
$self->stats->{$key}->{elapsed}, $key, |
47
|
|
|
|
|
|
|
$self->stats->{$key}->{count}, $speed; |
48
|
10
|
|
|
|
|
231
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
printf OUT "\n\n"; |
51
|
10
|
|
|
|
|
206
|
close(OUT); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
10
|
|
|
|
|
133
|
1; |
55
|
10
|
|
|
|
|
367
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=pod |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 NAME |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Catmandu::Fix::Bind::benchmark - a binder that calculates the execution time of Fix functions |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 SYNOPSIS |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
do benchmark(output:/dev/stderr) |
66
|
|
|
|
|
|
|
foo() |
67
|
|
|
|
|
|
|
end |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# will create as side effect computation statistics on the stderr |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
elapsed command calls sec/comm |
72
|
|
|
|
|
|
|
------------------------------------------------------------- |
73
|
|
|
|
|
|
|
0.000006 Catmandu::Fix::foo 1 times 0.000006 secs/command |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 DESCRIPTION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The benchmark binder computes all the Fix function plus as side effect |
78
|
|
|
|
|
|
|
calculates the execution time of all wrapped functions over all input records. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 CONFIGURATION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 output |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Required. The path of a file to which the benchmark statistics will be written. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L<Catmandu::Fix::Bind> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |