Created
July 21, 2013 07:08
-
-
Save bokutin/6047787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use Benchmark qw(:all); | |
use Data::Dumper; | |
use HTML::String; | |
use Test::Deep::NoTest; | |
use Text::Xslate qw(mark_raw html_escape); | |
my @goods = (qw(& and &)); | |
my @hs = (qw(& and), html('&')); | |
my @tx = (qw(& and), mark_raw('&')); | |
my $html = html(""); | |
sub hs { map { $html.$_ } @hs } | |
sub tx { map { "".html_escape($_) } @tx } | |
die unless eq_deeply([ hs ], \@goods ); | |
die unless eq_deeply([ tx ], \@goods ); | |
my $count = 5000*10; | |
cmpthese($count, { | |
'hs' => \&hs, | |
'tx' => \&tx, | |
}); | |
__END__ | |
% ./benchmark-auto-escape.pl | |
(warning: too few iterations for a reliable count) | |
Rate hs tx | |
hs 32323/s -- -92% | |
tx 426667/s 1220% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment