Created
April 16, 2010 04:07
-
-
Save gfx/367992 to your computer and use it in GitHub Desktop.
This file contains 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
$perl -Mblib benchmark/for.pl | |
Perl/5.10.1 i686-linux | |
Text::Xslate/0.001 | |
Text::MicroTemplate/0.11 | |
HTML::Template::Pro/0.94 | |
Rate mt ht xslate | |
mt 11270/s -- -20% -60% | |
ht 14092/s 25% -- -50% | |
xslate 28183/s 150% 100% -- |
This file contains 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
#!perl -w | |
use 5.010_000; | |
use strict; | |
use Text::Xslate::Compiler; | |
use Text::MicroTemplate qw(build_mt); | |
use HTML::Template::Pro; | |
use Benchmark qw(:all); | |
use Config; printf "Perl/%vd %s\n", $^V, $Config{archname}; | |
foreach my $mod(qw(Text::Xslate Text::MicroTemplate HTML::Template::Pro)){ | |
say $mod, '/', $mod->VERSION; | |
} | |
my $n = shift(@ARGV) || 10; | |
my $x = Text::Xslate::Compiler->new->compile_str(<<'TX_END'); | |
<ul> | |
? for $books ->($item) { | |
<li><?= $item.title ?></li> | |
? } | |
</ul> | |
TX_END | |
my $mt = build_mt(<<'MT_END'); | |
<ul> | |
? for my $item(@{$_[0]->{books}}) { | |
<li><?= $item->{title} ?></li> | |
? } | |
</ul> | |
MT_END | |
my $ht = HTML::Template->new(scalarref => \<<'HT_END', case_sensitive => 1); | |
<ul> | |
<tmpl_loop name="books"> | |
<li><tmpl_var name="title" escape="html"></li> | |
</tmpl_loop> | |
</ul> | |
HT_END | |
my %vars = ( | |
books => [( | |
{ title => 'Islands in the stream' }, | |
{ title => 'Beautiful code' }, | |
{ title => 'Introduction to Psychology' }, | |
{ title => 'Programming Perl' }, | |
{ title => 'Compilers: Principles, Techniques, and Tools' }, | |
) x $n], | |
); | |
$x->render(\%vars) eq $mt->(\%vars) or die $x->render(\%vars); | |
#$ht->param(\%vars);die $ht->output(); | |
# suppose PSGI response body | |
cmpthese -1 => { | |
xslate => sub { | |
my $body = [$x->render(\%vars)]; | |
return; | |
}, | |
mt => sub { | |
my $body = [$mt->(\%vars)]; | |
return; | |
}, | |
ht => sub{ | |
$ht->param(\%vars); | |
my $body = [$ht->output()]; | |
return; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment