Skip to content

Instantly share code, notes, and snippets.

@bokutin
Created July 21, 2013 07:08
Show Gist options
  • Save bokutin/6047787 to your computer and use it in GitHub Desktop.
Save bokutin/6047787 to your computer and use it in GitHub Desktop.
#!/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