| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2003 Fergal Daly distributed under the GNU |
|
2
|
|
|
|
|
|
|
# Lesser General Public License, you do not have to accept this license but |
|
3
|
|
|
|
|
|
|
# nothing else gives you the right to use this software |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
99074
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
44
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Test::Benchmark; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Test::Builder; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
997
|
use Benchmark qw( timethis timestr ); |
|
|
1
|
|
|
|
|
10412
|
|
|
|
1
|
|
|
|
|
6
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
146
|
use vars qw( |
|
15
|
|
|
|
|
|
|
$VERSION @EXPORT @ISA @CARP_NOT $VERBOSE |
|
16
|
1
|
|
|
1
|
|
469
|
); |
|
|
1
|
|
|
|
|
3
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = "0.004"; |
|
19
|
|
|
|
|
|
|
$VERBOSE = 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
require Exporter; |
|
24
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
|
25
|
|
|
|
|
|
|
@EXPORT = qw( is_faster is_n_times_faster is_fastest ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
|
|
1
|
|
6
|
use Carp qw( croak ); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
815
|
|
|
28
|
|
|
|
|
|
|
@CARP_NOT = qw( Test::Benchmark Benchmark ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub is_fastest |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
2
|
|
|
2
|
1
|
3932
|
my $which = shift; |
|
33
|
2
|
|
|
|
|
4
|
my $times = shift; |
|
34
|
2
|
|
|
|
|
4
|
my $marks = shift; |
|
35
|
2
|
|
|
|
|
4
|
my $name = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
2
|
|
|
|
|
3
|
my @marks; |
|
38
|
2
|
|
|
|
|
13
|
while (my ($name, $sub) = each %$marks) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
6
|
|
|
|
|
21
|
my $res = get_res($times, $sub); |
|
41
|
|
|
|
|
|
|
|
|
42
|
6
|
|
|
|
|
18782513
|
my($r, $pu, $ps, $cu, $cs, $n) = @$res; |
|
43
|
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
99
|
push(@marks, |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
|
|
|
|
|
|
name => $name, |
|
47
|
|
|
|
|
|
|
res => $res, |
|
48
|
|
|
|
|
|
|
n => $n, |
|
49
|
|
|
|
|
|
|
s => ($pu+$ps), |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
17
|
@marks = sort {$b->{n} * $a->{s} <=> $a->{n} * $b->{s}} @marks; |
|
|
6
|
|
|
|
|
23
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
6
|
my $ok = $marks[0]->{name} eq $which; |
|
57
|
|
|
|
|
|
|
|
|
58
|
2
|
|
|
|
|
18
|
$Test->ok($ok, $name); |
|
59
|
|
|
|
|
|
|
|
|
60
|
2
|
100
|
|
|
|
264
|
if (not $ok) |
|
61
|
|
|
|
|
|
|
{ |
|
62
|
1
|
|
|
|
|
5
|
$Test->diag("$which was not the fastest"); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
2
|
100
|
66
|
|
|
38
|
if (not $ok or $VERBOSE) |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
1
|
|
|
|
|
3
|
foreach my $mark (@marks) |
|
68
|
|
|
|
|
|
|
{ |
|
69
|
3
|
|
|
|
|
165
|
$Test->diag("$mark->{name} - ".timestr($mark->{res})); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_faster |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
5
|
|
|
5
|
1
|
11329
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
|
77
|
5
|
100
|
|
|
|
19
|
if (ref $_[1]) |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
4
|
|
|
|
|
13
|
is_n_times_faster(1, @_); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
else |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
1
|
|
|
|
|
4
|
is_n_times_faster(@_); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_n_times_faster |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
5
|
|
|
5
|
1
|
11
|
my $factor = shift; |
|
90
|
5
|
|
|
|
|
10
|
my $times = shift; |
|
91
|
5
|
|
|
|
|
7
|
my $code1 = shift; |
|
92
|
5
|
|
|
|
|
9
|
my $code2 = shift; |
|
93
|
5
|
|
|
|
|
8
|
my $name = shift; |
|
94
|
|
|
|
|
|
|
|
|
95
|
5
|
|
|
|
|
9
|
my @res; |
|
96
|
|
|
|
|
|
|
|
|
97
|
5
|
|
|
|
|
11
|
my ($res1, $res2) = map {get_res($times, $_)} ($code1, $code2); |
|
|
10
|
|
|
|
|
10691296
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
7833524
|
my($r1, $pu1, $ps1, $cu1, $cs1, $n1) = @$res1; |
|
100
|
5
|
|
|
|
|
17
|
my($r2, $pu2, $ps2, $cu2, $cs2, $n2) = @$res2; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# we want code1 to be faster than code2. Essentially we are comparing 2 |
|
103
|
|
|
|
|
|
|
# fractions factor * n1/cpu1 > n2/cpu2 but in order to avoid div by zero |
|
104
|
|
|
|
|
|
|
# we use multiplication |
|
105
|
|
|
|
|
|
|
|
|
106
|
5
|
|
|
|
|
27
|
my $ok = ($n1 * ($pu2 + $ps2) * $factor) > ($n2 * ($pu1 + $ps1)); |
|
107
|
5
|
|
|
|
|
46
|
$Test->ok($ok, $name); |
|
108
|
|
|
|
|
|
|
|
|
109
|
5
|
100
|
|
|
|
791
|
if (not $ok) |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
3
|
100
|
|
|
|
15
|
my $extra = ($factor == 1) ? "" : " at least $factor times"; |
|
112
|
3
|
|
|
|
|
21
|
$Test->diag("code1 was not$extra faster than code 2"); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
5
|
100
|
66
|
|
|
86
|
if (not $ok or $VERBOSE) |
|
116
|
|
|
|
|
|
|
{ |
|
117
|
3
|
|
|
|
|
37
|
$Test->diag(timestr($res1)); |
|
118
|
3
|
|
|
|
|
299
|
$Test->diag(timestr($res2)); |
|
119
|
|
|
|
|
|
|
} |
|
120
|
5
|
|
|
|
|
205
|
return $ok; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub get_res |
|
124
|
|
|
|
|
|
|
{ |
|
125
|
16
|
|
|
16
|
0
|
39
|
my ($times, $sub) = @_; |
|
126
|
|
|
|
|
|
|
|
|
127
|
16
|
50
|
|
|
|
59
|
if (ref($sub) eq "Benchmark") |
|
128
|
|
|
|
|
|
|
{ |
|
129
|
0
|
|
|
|
|
0
|
return $sub; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
elsif (0) |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
|
|
|
|
|
|
# get from cache not implemented - maybe never will be... |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
else |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
16
|
|
|
|
|
63
|
return timethis($times, $sub, "", "none"); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub builder |
|
142
|
|
|
|
|
|
|
{ |
|
143
|
1
|
50
|
|
1
|
0
|
27
|
if (@_) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
1
|
|
|
|
|
3
|
$Test = shift; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
1
|
|
|
|
|
3
|
return $Test; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |