Surveyor::Benchmark::HTMLEntities - Benchmark HTML entity escaping
Install Surveyor::App to get the survey program.
survey
To test the defaults:
% survey -p Surveyor::Benchmark::HTMLEntities URL
To compare pure Perl behavior:
% env PERL_ONLY=1 survey -p Surveyor::Benchmark::HTMLEntities URL
HTML::Escape provides a limited functionality HTML entity escaper. It only handles ><&"'. As such, it can be quite a bit faster because it does less.
><&"'
Here are some numbers from my Mid-2012 MacBook Air:
XS versus pure Perl:
Benchmark: timing 10000 iterations of html_entities, html_escape... html_entities: 14 wallclock secs (14.09 usr + 0.01 sys = 14.10 CPU) @ 709.22/s (n=10000) html_escape: 1 wallclock secs ( 0.68 usr + 0.00 sys = 0.68 CPU) @ 14705.88/s (n=10000)
fair fight:
Benchmark: timing 10000 iterations of html_entities, html_escape... html_entities: 14 wallclock secs (13.79 usr + 0.01 sys = 13.80 CPU) @ 724.64/s (n=10000) html_escape: 7 wallclock secs ( 7.57 usr + 0.01 sys = 7.58 CPU) @ 1319.26/s (n=10000)
Fetch the web page and store it for use in the benchmarks.
Use HTML::Escape to encode. This is an XS module.
HTML::Escape only encodes the ><&"'.
Use HTML::Entities to encode. This is an pure Perl module.
I tell encode_entities to only encode ><&"' so it matches what HTML::Escape will do. Otherwise, encode_entities escapes wide characters too.
encode_entities
This source is in Github:
https://github.com/briandfoy/surveyor-benchmark-htmlentities
brian d foy, <briandfoy@pobox.com>
<briandfoy@pobox.com>
Copyright © 2013-2024, brian d foy <briandfoy@pobox.com>. All rights reserved.
You may redistribute this under the terms of Artistic License 2.0.
To install Surveyor::Benchmark::HTMLEntities, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Surveyor::Benchmark::HTMLEntities
CPAN shell
perl -MCPAN -e shell install Surveyor::Benchmark::HTMLEntities
For more information on module installation, please visit the detailed CPAN module installation guide.