line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tool::Bench::Report::Text; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Tool::Bench::Report::Text::VERSION = '0.003'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
10
|
use Mouse; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
836
|
use List::Util qw{min max sum }; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
423
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: How to build the Text Report |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
At the very end of everything, you will likely want a nice clean report of |
13
|
|
|
|
|
|
|
everything. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $bench = Tool::Bench->new; |
16
|
|
|
|
|
|
|
$bench->add_items( true => sub{1}, |
17
|
|
|
|
|
|
|
die => sub{die}, |
18
|
|
|
|
|
|
|
ls => {code => sub{qx{ls}}, |
19
|
|
|
|
|
|
|
note => 'some note', |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
sleep => sub{sleep(1)}, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
$bench->run(4); |
24
|
|
|
|
|
|
|
print $bench->report(format => 'Text'); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
min max total avg count name |
27
|
|
|
|
|
|
|
0.000 0.000 0.000 0.000 4 true |
28
|
|
|
|
|
|
|
0.000 0.000 0.000 0.000 4 die |
29
|
|
|
|
|
|
|
0.002 0.002 0.009 0.002 4 ls [some note] |
30
|
|
|
|
|
|
|
1.000 1.000 4.000 1.000 4 sleep |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 report |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This is the method that $bench->report will call to build the actual report. |
37
|
|
|
|
|
|
|
The most important thing that is passed along by $bench is the item objects. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$bench->report(format => 'Text'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Will end up calling 'report' looking like: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Tool::Bench::Report::Text->new->report(items => [...]); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Common practice is that you return the report, rather then printing. This |
46
|
|
|
|
|
|
|
allows the user to decide what they want to do with that report on there end. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub report { |
51
|
1
|
|
|
1
|
1
|
76
|
my ($self,%args) = @_; |
52
|
|
|
|
|
|
|
|
53
|
4
|
100
|
|
|
|
17
|
sprintf qq{%s\n\n}, |
54
|
|
|
|
|
|
|
join qq{\n}, |
55
|
|
|
|
|
|
|
q{ min max total avg count name}, |
56
|
5
|
|
|
|
|
27
|
map{ sprintf q{%0.3f %0.3f %0.3f %0.3f % 5d %s %s}, |
57
|
|
|
|
|
|
|
$_->min_time, |
58
|
|
|
|
|
|
|
$_->max_time, |
59
|
|
|
|
|
|
|
$_->total_time, |
60
|
|
|
|
|
|
|
$_->avg_time, |
61
|
|
|
|
|
|
|
$_->total_runs, |
62
|
|
|
|
|
|
|
$_->name, |
63
|
|
|
|
|
|
|
#length($_->note) ? sprintf q{[NOTE: %s]}, $_->note : '' |
64
|
|
|
|
|
|
|
length($_->note) ? sprintf q{[%s]}, $_->note : '' |
65
|
1
|
|
|
|
|
2
|
} sort {$a->total_time <=> $b->total_time} @{$args{items}}; |
|
1
|
|
|
|
|
7
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|