line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
708
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Surveyor::Benchmark::HTMLEntities; |
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.023'; |
8
|
|
|
|
|
|
|
our $HTML; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
436
|
use HTML::Entities; |
|
1
|
|
|
|
|
6026
|
|
|
1
|
|
|
|
|
86
|
|
11
|
1
|
|
|
1
|
|
490
|
use HTML::Escape; |
|
1
|
|
|
|
|
1233
|
|
|
1
|
|
|
|
|
354
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Surveyor::Benchmark::HTMLEntities - Benchmark HTML entity escaping |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Install L to get the C program. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
To test the defaults: |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
% survey -p Surveyor::Benchmark::HTMLEntities URL |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
To compare pure Perl behavior: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
% env PERL_ONLY=1 survey -p Surveyor::Benchmark::HTMLEntities URL |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
L provides a limited functionality HTML entity escaper. |
34
|
|
|
|
|
|
|
It only handles C<< ><&"' >>. As such, it can be quite a bit faster |
35
|
|
|
|
|
|
|
because it does less. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Here are some numbers from my Mid-2012 MacBook Air: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
XS versus pure Perl: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Benchmark: timing 10000 iterations of html_entities, html_escape... |
42
|
|
|
|
|
|
|
html_entities: 14 wallclock secs (14.09 usr + 0.01 sys = 14.10 CPU) @ 709.22/s (n=10000) |
43
|
|
|
|
|
|
|
html_escape: 1 wallclock secs ( 0.68 usr + 0.00 sys = 0.68 CPU) @ 14705.88/s (n=10000) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
fair fight: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Benchmark: timing 10000 iterations of html_entities, html_escape... |
48
|
|
|
|
|
|
|
html_entities: 14 wallclock secs (13.79 usr + 0.01 sys = 13.80 CPU) @ 724.64/s (n=10000) |
49
|
|
|
|
|
|
|
html_escape: 7 wallclock secs ( 7.57 usr + 0.01 sys = 7.58 CPU) @ 1319.26/s (n=10000) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 4 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item set_up( URL ) |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Fetch the web page and store it for use in the benchmarks. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub set_up { |
60
|
0
|
|
|
0
|
1
|
|
my( $self, @args ) = @_; |
61
|
0
|
|
|
|
|
|
require Mojo::UserAgent; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
print "Fetching $args[0]\n"; |
64
|
0
|
|
|
|
|
|
my $tx = Mojo::UserAgent->new->get( $args[0] ); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $code = $tx->res->code; |
67
|
0
|
0
|
|
|
|
|
die "Status $code: Could not fetch $args[0]\n" |
68
|
|
|
|
|
|
|
unless $code == 200; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$HTML = $tx->res->body; |
71
|
0
|
|
|
|
|
|
print "HTML is " . length($HTML) . " bytes\n"; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my %counts; |
74
|
0
|
|
|
|
|
|
$counts{'>'} = $HTML =~ tr/>//; |
75
|
0
|
|
|
|
|
|
$counts{'<'} = $HTML =~ tr//; |
76
|
0
|
|
|
|
|
|
$counts{'&'} = $HTML =~ tr/&//; |
77
|
0
|
|
|
|
|
|
$counts{"'"} = $HTML =~ tr/'//; |
78
|
0
|
|
|
|
|
|
$counts{'"'} = $HTML =~ tr/"//; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
printf qq(> (%d)\n< (%d)\n& (%d)\n' (%d)\n" (%d)\n), |
81
|
0
|
|
|
|
|
|
@counts{ qw(> < & ' ") }; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item tear_down |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub tear_down { |
89
|
0
|
|
|
0
|
1
|
|
1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item bench_html_escape |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Use HTML::Escape to encode. This is an XS module. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
HTML::Escape only encodes the C<< ><&"' >>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub bench_html_escape { |
101
|
0
|
|
|
0
|
1
|
|
my $escaped = HTML::Escape::escape_html( $HTML ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item bench_html_entities |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Use HTML::Entities to encode. This is an pure Perl module. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
I tell C to only encode C<< ><&"' >> so it |
109
|
|
|
|
|
|
|
matches what HTML::Escape will do. Otherwise, C |
110
|
|
|
|
|
|
|
escapes wide characters too. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub bench_html_entities { |
115
|
0
|
|
|
0
|
1
|
|
my $escaped = HTML::Entities::encode_entities( $HTML, q(<>&"') ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=back |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 TO DO |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 SEE ALSO |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This source is in Github: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
https://github.com/briandfoy/surveyor-benchmark-htmlentities |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
brian d foy, C<< >> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright © 2013-2022, brian d foy . All rights reserved. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You may redistribute this under the terms of Artistic License 2.0. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |