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